How does incr work with expiry times?

十年热恋 提交于 2020-01-14 11:57:46

问题


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?


回答1:


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




回答2:


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)



来源:https://stackoverflow.com/questions/1890682/how-does-incr-work-with-expiry-times

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!