Reputation: 481
I am using Google App Engine for my application and for reducing the datastore costs i am extensively using memcache.
Example of a snippet given below,
val = memcache.get('forum')
if val is None:
val = 'stackoverflow'
memcache.add('forum', val, time=600)
return val
The time expiration I have set is for 10 mins (600/60 = 10 mins), and the value is not in cache after 10 mins, but in app engine memcache document its says the values will not be evicted as below ( as time is only an optional parameter)
add(key, value, time=0, min_compress_len=0, namespace=None)source Sets a key's value, iff item is not already in memcache.
Parameters key -- Key to set. See docs on Client for details.
value -- Value to set. Any type. If complex, will be pickled.
time -- Optional expiration time, either relative number of seconds from current time (up to 1 month), or an absolute Unix epoch time. By default, items never expire, though items may be evicted due to memory pressure. Float values will be rounded up to the nearest whole second. min_compress_len -- Ignored option for compatibility. namespace -- a string specifying an optional namespace to use in the request. Returns True if added. False on error.
I am also using a Dedicated memcache, it says the items will never expire, but in my case the items expires when I set the time (for eg: time=600s), why it is so ??
Upvotes: 0
Views: 1493
Reputation: 39814
From How cached data expires (emphasis mine):
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 is evicted no later than this time, though it can be evicted earlier for other reasons.
Upvotes: 1