views:

170

answers:

1

Is there support for sliding expiration in the GAE MemcacheService? I can do a crude implementation where following every get() I do a put(). This will effectively reset the expiration time but this obviously is not an efficient solution.

Any pointers on how I can implement this more efficiently?

Thanks, Keyur

+2  A: 

A cache is typically an LRU (Least Recently Used). It is not recommended to manipulate this, if you do you are probably using the wrong mechanism.

That being said, your scheme should work in most cases, once again, but why ?

As per http://code.google.com/appengine/docs/java/memcache/overview.html

How Cached Data Expires By default, values stored in memcache are retained as long as possible. Values may be evicted from the cache when a new value is added to the cache if the cache is low on memory. When values are evicted due to memory pressure, the least recently used values are evicted first. The app can provide an expiration time when a value is stored, as either a number of seconds relative to when the value is added, or as an absolute Unix epoch time in the future (a number of seconds from midnight January 1, 1970). The value will be evicted no later than this time, though it may be evicted for other reasons. Under rare circumstances, values may also disappear from the cache prior to expiration for reasons other than memory pressure. While memcache is resilient to server failures, memcache values are not saved to disk, so a service failure may cause values to become unavailable. In general, an application should not expect a cached value to always be available.

Romain Hippeau
If the GAE memcache is indeed LRU then I'm gold. Is there any documentation on it being LRU?
Keyur