Writing cachemean Function