made average cache function