If you need to speed up your Python application, you should take a look at plone.memoize, in particular its new cache decorator that's really easy to use:
>>> from plone.memoize.ram import cache >>> def cache_key(fun, first, second): ... return (first, second) >>> @cache(cache_key) ... def pow(first, second): ... print 'Someone or something called me' ... return first ** second >>> pow(3, 2) Someone or something called me 9 >>> pow(3, 2) 9 >>> pow(3, 3) Somone or something called me 27
You can see that the cache key function determines which input values result in the same output and thus can be cached. Cache key functions receive exactly the same arguments as the functions that they cache, plus the function itself. Thus, key functions for methods can also use self for determining a cache key. A cache key function may raise the DontCache exception to signal that no caching should take place.
The cache storage backend can be freely chosen using the second argument to the cache decorator:
>>> @cache(cache_key, cache_storage)
where cache_storage is a function that again takes all arguments of the original function and returns a dict-like object for use as a cache storage. plone.memoize has built-in support for memcached and zope.app.cache as storages.
See the doctests for volatile.py for more examples.
For now, you'll need to use the SVN version. A release containing the cache decorator will follow soon.
posted at: 22:10 |
0 comments |
category: /devel
|
permanent link |
add to del.icio.us or digg it
Tom thought it'd be a good idea to write down what we were up to at the PIKtipi sprint (2nd to 7th of June), so here's my wrap-up:
PIKtipi was my third Plone sprint so far in 2007. I had an excellent, and productive time, thanks to all organizers. Here's what I did:
- Develop further plone.memoize and make use of it in the portlets implementation of Plone 3. Together with Hanno, we were able to speed up Plone for anonymous users by about 50%, and for logged in users by about a third. Stefan helped me implement the memcached support.
- Fix some bugs for the 3.0 release of Plone. By the way, if you're one of the 145 Plone providers earning money with Plone, you should consider helping out. Plone 3 will have loads of new features, but that also means that the bugtracker needs increased attention to get all these features stable.
- Have a fun time with fellow Plone developers, and attend the DZUG conference that was running in parallel.
- In Berlin, run into a 3 hour DJ set by Ellen Allien by accident. Thanks to Siebo and Saskia for their great company. :-)
posted at: 14:48 |
0 comments |
category: /devel/zope
|
permanent link |
add to del.icio.us or digg it
| < | June 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 |
Feed of all categories:
rss |
atom