Memcache / Bug report and patch

3 views
Skip to first unread message

NicolasB

unread,
Apr 28, 2009, 12:46:23 PM4/28/09
to web2py Web Framework
Hi all,

I think I found an issue into gluon\contrib\memcache\__init__.py

The 'key' parameter is missing for 'set' function
And I had to add "import time" to make it work

Hope this help here as I don't know where to post a patch.
Regards,
Nicolas

Here is the modified code:
-------------------
from gluon.contrib.memcache.memcache import Client
import time

"""
examle of usage:

cache.memcache=MemcacheClient(request,[127.0.0.1:11211],debug=true)
"""

import cPickle as pickle

class MemcacheClient(Client):
def __init__(self, request, servers, debug=0, pickleProtocol=0,
pickler=pickle.Pickler, unpickler=pickle.Unpickler,
pload=None, pid=None):
self.request=request
Client.__init__(self,servers,debug,pickleProtocol,
pickler,unpickler,pload,pid)
def __call__(self,key,f,time_expire=300):
key='%s/%s' % (self.request.application,key)
dt=time_expire
value=None
obj=self.get(key)
if obj and obj[0]>time.time()-dt:
value=obj[1]
elif f is None:
if obj: self.delete(key)
else:
value=f()
self.set(key,(time.time(),value))
return value
def increment(self,key,value=1):
key='%s/%s' % (self.request.application,key)
obj=self.get(key)
if obj: value=obj[1]+value
self.set(key,(time.time(),value))
return value

mdipierro

unread,
Apr 28, 2009, 1:38:46 PM4/28/09
to web2py Web Framework
Thank you. I will post it to trunk asap.

mdipierro

unread,
Apr 28, 2009, 5:14:00 PM4/28/09
to web2py Web Framework
fixed in trunk. Can you please email me your last name so I can add
your name to the list of contributors.

Massimo

On Apr 28, 11:46 am, NicolasB <nicolas.bn...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages