plomino/Plomino — Issue #43: Provide a caching mechanism
Author: ebrehault
Created: 2011-11-23 09:18:03+00:00
State: open

Sometimes, when rendering a document using a form, several computed fields make the same computing (typical example: you display a table of values, and also a bar chart based on those values).

The code itself can be factorized using a script librarie in /resources folder, but it will be run twice anyway when rendering the page.

It might impact the performances.

So the idea is to provides a cache mechanism like that:
result = db.getCache('my_cache_key')
if not result:
result = []
for stuff in large_set_of_stuf:
result.append(make_something_which_cost_CPU(stuff))
db.setCache('my_cache_key', result, duration=1000)

return result

As always with cache, everything depend on the cache key, it can be computed based on any parameter we wnat, including the user id if needed.

It could be based on plone.memoize I guess.