Memcache & SQL Query as key

14 views
Skip to first unread message

NicolasB

unread,
May 6, 2009, 11:45:21 AM5/6/09
to web2py Web Framework
Hello,
I am using memcache to hold query directly:
db((db.ad...,cache=(cache.mem,100))

Web2py creates a key with the query. However memcache does not seem to
support spaces.

I modified web2py_src_1.61.4\web2py\gluon\contrib\memcache\__init__.py
to format the key

I don't know if this is the best way to do...

Best regards,
Nicolas

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=self.__keyFormat__(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=self.__keyFormat__(key)
obj=self.get(key)
if obj: value=obj[1]+value
self.set(key,(time.time(),value))
return value

def __keyFormat__(self,key):
return '%s/%s' % (self.request.application,key.replace('
','_'))

mdipierro

unread,
May 6, 2009, 12:34:47 PM5/6/09
to web2py Web Framework
Can you please email me the modified file? Thanks.

NicolasB

unread,
May 7, 2009, 4:53:17 AM5/7/09
to web2py Web Framework
Finally, I keep working on it. I will suggest to add a few other
modification.
Still testing and then posting it.

Regards,
Nicolas

NicolasB

unread,
May 20, 2009, 5:11:59 AM5/20/09
to web2py Web Framework, NicolasB
I have sent you an email with my changes.
Best regards,
Nicolas

On 7 mai, 10:53, NicolasB <nicola...@gmail.com> wrote:
> Finally, I keep working on it. I will suggest to add a few other
> modification.
> Still testing and then posting it.
>
> Regards,
> Nicolas
>
> On 6 mai, 18:34, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > Can you please email me the modified file? Thanks.
>
> > On May 6, 10:45 am, NicolasB <nicolas.bn...@gmail.com> wrote:
>
> > > Hello,
> > > I am usingmemcacheto hold query directly:
> > > db((db.ad...,cache=(cache.mem,100))
>
> > > Web2py creates a key with the query. Howevermemcachedoes not seem to
> > > support spaces.
>
> > > I modified web2py_src_1.61.4\web2py\gluon\contrib\memcache\__init__.py
> > > to format the key
>
> > > I don't know if this is the best way to do...
>
> > > Best regards,
> > > Nicolas
>
> > > from gluon.contrib.memcache.memcacheimport Client

mdipierro

unread,
May 20, 2009, 8:55:39 AM5/20/09
to web2py Web Framework
thanks.

On May 20, 4:11 am, NicolasB <nicolas.bn...@gmail.com> wrote:
> I have sent you an email with my changes.
> Best regards,
> Nicolas
>
Reply all
Reply to author
Forward
0 new messages