adapted from cache mean