[Zope3-Users] Using RAMCache

Bernd Dorn bernd.dorn at lovelysystems.com
Tue Jul 3 17:19:45 EDT 2007


On 03.07.2007, at 13:47, Dominique Lederer wrote:

> hi
>
> i would like to cache the results of method in a view, and thougt,  
> that RAMCache
> could be of use here.
>
> After spending a lot of time searching for some documentation or  
> examples, i
> came to this:
>
> from zope.app.cache.ram import RAMCache
> cache = RAMCache()
> query = cache.query('test',key={'x':1})
> if query == None:
> 	result = expensive_stuff_method()
>   	cache.set(result, 'test', key={'x':1})
> 	return result
> else:
> 	return query
>
> but that won´t work, the cache looses it´s entry, if i call the  
> browser-view again.
>
> any hints?
> thanks, Dominique

for a direct usage of ramcache (not as utility) you can instantiate  
one in your module, as an example see

http://svn.zope.org/z3c.image/trunk/src/z3c/image/proc/adapter.py? 
rev=76889&view=auto

(forget about the ulimit stuff there)

note that if you have zeo with multiple zope instances the cache is  
not shared across instances, if you have such a setop, a good option  
is lovely.memcached

http://svn.zope.org/lovely.memcached/trunk/

distributions are on http://download.zope.org/distribution/

regards, bernd

>
> _______________________________________________
> Zope3-users mailing list
> Zope3-users at zope.org
> http://mail.zope.org/mailman/listinfo/zope3-users



More information about the Zope3-users mailing list