When I have some data to put in the cache, I do it the easiest way: I write a python script that returns the data and then from the Zope Instance Manager I make use of the caching Tab to select the type of caching.
Anton (the speaker) showed me a way of using zope caching form within my code:
and then make my class (Content Type, Tool or ...) cacheable by inheriting from Cacheable.
To cache and to get cached data, we can use some thing like this:
Easy no?
I wonder why this technique is not used inside the portal_catalog to cache the searchResults of last N or most used queries.
Anton (the speaker) showed me a way of using zope caching form within my code:
from OFS.Cache import Cacheable
and then make my class (Content Type, Tool or ...) cacheable by inheriting from Cacheable.
To cache and to get cached data, we can use some thing like this:
view_name = 'my_view'
# get cached data
cached_data = self.ZCacheable_get(view_name = view_name,
default = None)
if cached_data is not None:
return cached_data
else:
# no data in the cache, so cache it
data_to_cache = self._getData()
self.ZCacheable_set(data_to_cache, view_name=view_name)
return data_to_cache
Easy no?
I wonder why this technique is not used inside the portal_catalog to cache the searchResults of last N or most used queries.