[Zope] Python, persistent objects and caching
Hi, I'm developing a Python-based product that uses persistent objects in ZODB to store its configuration. No surprises there, but my product is also using volatile attributes to do a bit of caching of its own. The thing is, when ZODB takes a sweep every 60 seconds to flush it's own cache it will quite often flush my product as well, essentially rendering my 15 minute caching ineffective. If there a way I can prevent this from happening? References: http://www.zope.org/Members/MikeP/volatile http://www.zope.org/Members/Zen/tips/VolatileAttributes Soren Roug ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
RE: [Zope] Python, persistent objects and caching
I'm developing a Python-based product that uses persistent objects in ZODB to store its configuration. No surprises there, but my product is also using volatile attributes to do a bit of caching of its own. The thing is, when ZODB takes a sweep every 60 seconds to flush it's own cache it will quite often flush my product as well, essentially rendering my 15 minute caching ineffective. If there a way I can prevent this from happening? References: http://www.zope.org/Members/MikeP/volatile http://www.zope.org/Members/Zen/tips/VolatileAttributes Soren Roug One approach would be to cache your data in the module's namespace. For ex: mycache={} class MyClassThatKeepsGoingAway: ... def get_data(self, id): if mycache.has_key(id): return mycache[id] else: ... Note that my example is a little contrived, since using a module variable means that you will have to implement this in a way that is safe for a multi-threaded environment. You will also want to make sure that your module-level cache doesn't grow forever and take up a lot of memory. Hope this helps! Brian Lloyd ([EMAIL PROTECTED]) ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
RE: [Zope] Python, persistent objects and caching
Brian Lloyd writes: Soren Rough writes ... application level cache ... ... application objects flushed (including cache) One approach would be to cache your data in the module's namespace. For ex: mycache={} class MyClassThatKeepsGoingAway: ... def get_data(self, id): if mycache.has_key(id): return mycache[id] else: ... Note that my example is a little contrived, since using a module variable means that you will have to implement this in a way that is safe for a multi-threaded environment. You can use a "SharedResource" for this: URL:http://www.dieter.handshake.de/pyprojects/zope/SharedResource.html Dieter ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )