Will McGugan recently blogged about his timed caching decorator. And today I found out about gocept.cache, which allows you to memoize a function for a given amount of seconds.
This is how you would cache a function's value for an hour using plone.memoize:
>>> from time import time >>> from plone.memoize import ram >>> @ram.cache(lambda *args: time() // (60 * 60)) ... def fun(): ... return "Something that takes awfully long"
In the same way we're making the cache depend on time here, we could have it depend on anything else, like certain arguments provided to the function. So, really, we can do more than just memoization with plone.memoize; an example is this time-out application.
See the plone.memoize docs for more examples.
posted at: 14:35 |
0 comments |
category: /devel
|
permanent link |
add to del.icio.us or digg it
| < | October 2007 | > | ||||
| Su | Mo | Tu | We | Th | Fr | Sa |
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 | |||
Feed of all categories:
rss |
atom