Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does incr work with expiry times?

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?

like image 754
ʞɔıu Avatar asked Dec 11 '09 20:12

ʞɔıu


2 Answers

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

like image 179
Juan E. Avatar answered Nov 14 '22 07:11

Juan E.


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)

like image 1
Dustin Avatar answered Nov 14 '22 08:11

Dustin