Programmatically flushing entries from RAM cache?
Is it possible to flush a path w/ a specific argument from a RAM cache from a Python script? Here's my situation: I have a script FolderExists() that takes a single "path" argument and, after running an SQL query, returns True or False if the folder path exists or not in the database. Since the database query is relatively expensive, I want to cache its result in RAM. However, if a folder is created (using another Python script in the same Zope instance) I want to flush the cached result for the path (i.e., I don't want to flush all of the cached entries for the FolderExists method if that can be avoided). TIA, John
On Thu, Dec 15, 2005 at 11:45:51AM +0900, John Barham wrote:
Is it possible to flush a path w/ a specific argument from a RAM cache from a Python script?
I'm not sure what the "specific argument" refers to, but in general, sure. Just do this: ob = context.restrictedTraverse(some_path) ob.ZCacheable_invalidate() But I think you need the "View management screens" permission. (I have no idea why that one was chosen.) -- Paul Winkler http://www.slinkp.com
John Barham wrote:
Is it possible to flush a path w/ a specific argument from a RAM cache from a Python script?
Here's my situation: I have a script FolderExists() that takes a single "path" argument and, after running an SQL query, returns True or False if the folder path exists or not in the database. Since the database query is relatively expensive, I want to cache its result in RAM. However, if a folder is created (using another Python script in the same Zope instance) I want to flush the cached result for the path (i.e., I don't want to flush all of the cached entries for the FolderExists method if that can be avoided).
Unfortunately no, it's a deficiency of the simple RAMCacheManager: you can't invalidate a key individually, you have to invalidate them all. Changing this is probably not too complex, and is (low) on my TODO list (at position approx. 136 ;)). Florent -- Florent Guillaume, Nuxeo (Paris, France) CTO, Director of R&D +33 1 40 33 71 59 http://nuxeo.com fg@nuxeo.com
participants (3)
-
Florent Guillaume -
John Barham -
Paul Winkler