views:

36

answers:

2

In memcached (appengine api implementation), how does expiration interact with incr()? There isn't a time argument for incr(), but what happens if I add the key with another call rather than using the initial_value param, like so:

memcache.add('testcounter', 0, time=60*90) 
newcnt = memcache.incr('testcounter')

will testcounter still expire in 90 minutes? Whether or not I call this again in that time?

A: 

The expiration time is not affected by incr.

That object will expire from the cache no later than 90 seconds after you add it regardless of the number of times you incr it.

(and, of course, it may expire sooner)

Dustin
I'd love to +1 but is this documented somewhere?
jhs
+2  A: 

In the memcache overview of GAE they say:

"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." it doesn't mention modifications.

If you look at the code of memcache in google.appengine.api.memcache.init.py you'll see that neither in incr or in _incrdecr there is a call to the set_expiration_time function

Chedar