Beaker: 'expiretime' and memcached backend

25 views
Skip to first unread message

Andrew Stromnov

unread,
Feb 21, 2008, 5:53:04 AM2/21/08
to pylons-devel
Is 'expiretime' passed to memcached backend?

It seems that 'key:value; pair stays forever in memcached backend.

Ben Bangert

unread,
Feb 21, 2008, 1:52:57 PM2/21/08
to pylons...@googlegroups.com
On Feb 21, 2008, at 2:53 AM, Andrew Stromnov wrote:

> Is 'expiretime' passed to memcached backend?
>
> It seems that 'key:value; pair stays forever in memcached backend

The expired time isn't passed to the backends, when Beaker stores a
value in any backend, it records the stored time in addition to the
value. Then upon retrieval of the value (and its stored time), it does
a check against the expiration to see if the value has expired, and
recreates it if it has. Until Beaker next accesses and invalidates the
value, it will not be removed from the backend.

Cheers,
Ben

Andrew Stromnov

unread,
Feb 27, 2008, 11:14:38 AM2/27/08
to pylons-devel
stromnov@stromnov-desktop:~/Projects/beaker-bug$ cat step1.py
# -*- coding: utf-8 -*-

import time
from beaker.cache import CacheManager

mem_manager = CacheManager(type="memory")
mem_cache = mem_manager.get_cache("test")
mem_cache.clear()

mc_manager = CacheManager( type="ext:memcached",
url="localhost:11211", lock_dir="./mcd_lock")
mc_cache = mc_manager.get_cache("test")
mc_cache.clear()

def cachetest(cache, key):
try:
value = cache[key]
return "hit"
except KeyError:
return "miss"

mem_cache.set_value("key", "value", expiretime=7)
mc_cache.set_value("key", "value", expiretime=7)

for t in range(4):
print t, "mem", cachetest(mem_cache, "key")
print t, "mc ", cachetest(mc_cache, "key")
time.sleep(1)


stromnov@stromnov-desktop:~/Projects/beaker-bug$ cat step2.py
# -*- coding: utf-8 -*-

import time
from beaker.cache import CacheManager

mem_manager = CacheManager(type="memory")
mem_cache = mem_manager.get_cache("test")

mc_manager = CacheManager( type="ext:memcached",
url="localhost:11211", lock_dir="./mcd_lock")
mc_cache = mc_manager.get_cache("test")

def cachetest(cache, key):
try:
value = cache[key]
return "hit"
except KeyError:
return "miss"

for t in range(4):
print t, "mem", cachetest(mem_cache, "key")
print t, "mc ", cachetest(mc_cache, "key")
time.sleep(1)

stromnov@stromnov-desktop:~/Projects/beaker-bug$ python step1.py; echo
"pass 2"; python step2.py
0 mem hit
0 mc hit
1 mem hit
1 mc hit
2 mem hit
2 mc hit
3 mem hit
3 mc hit
pass 2
0 mem miss
0 mc hit
1 mem miss
1 mc hit
2 mem miss
2 mc hit
3 mem miss
3 mc hit

So, memcache stored value forever, if application was restarted.
In many cases memcached backend used by many apps together, so clear()
method should be avoided.

I think that 'expiretime' should be passed to memcache backend.
> smime.p7s
> 3KЗагрузить
Reply all
Reply to author
Forward
0 new messages