Cache feature

32 views
Skip to first unread message

Amine Salmen Rekik

unread,
Apr 24, 2014, 1:06:52 PM4/24/14
to nagare...@googlegroups.com
Hello,

Does nagare implement cache feature? Indeed, I have some data retrieved from DB and I need to add them to cache to minimize the requests to DB.

Thanks

Alain Poirier

unread,
Apr 25, 2014, 11:00:47 AM4/25/14
to nagare...@googlegroups.com
Hi,

Le 24 avr. 2014 à 19:06, Amine Salmen Rekik <amine...@gmail.com> a écrit :

> Hello,
>
> Does nagare implement cache feature? Indeed, I have some data retrieved from DB and I need to add them to cache to minimize the requests to DB.

Nagare doesn’t provide a database cache service.

Sometimes when we want to cache some DB requests during the processing of a
HTTP request, we use a function decorator like this:

# ----------
from nagare.local import request

def cached(f):
#
# @cached
# def do_some_db_requests(self, …):
# ...
# return …
#
def _(self):
cache = request.__dict__.setdefault('cache', {})

key = (id(f), id(self))

if key in cache:
r = cache[key]
else:
r = f(self)
cache[key] = r

return r

return _
# ----------

> Thanks

Best regards,
Alain

Amine Salmen Rekik

unread,
Apr 28, 2014, 2:49:54 AM4/28/14
to nagare...@googlegroups.com
Thank you :-)
Reply all
Reply to author
Forward
0 new messages