diff roundup/roundupdb.py @ 4652:dfbc0cfa9811

Add an interface to register clearCache callbacks in roundupdb. Sometimes complicated computations may require an application cache. This application can now register a callback to clear the application cache, because roundup knows better when to clear it (usually when a transaction ends, either with rollback or with commit). The interface for this is currently considered experimental. The current interface is registerClearCacheCallback(self, method, param) where method is called with param as the only parameter.
author Ralf Schlatterbeck <rsc@runtux.com>
date Fri, 17 Aug 2012 15:30:36 +0200
parents d9d7319afffa
children 9cc6d463cfbe
line wrap: on
line diff
--- a/roundup/roundupdb.py	Sat Jul 14 02:39:23 2012 +0200
+++ b/roundup/roundupdb.py	Fri Aug 17 15:30:36 2012 +0200
@@ -149,6 +149,26 @@
 
         return self.__logger
 
+    def clearCache(self):
+        """ Backends may keep a cache.
+            It must be cleared at end of commit and rollback methods.
+            We allow to register user-defined cache-clearing routines
+            that are called by this routine.
+        """
+        if getattr (self, 'cache_callbacks', None) :
+            for method, param in self.cache_callbacks:
+                method(param)
+
+    def registerClearCacheCallback(self, method, param = None):
+        """ Register a callback method for clearing the cache.
+            It is called with the given param as the only parameter.
+            Even if the parameter is not specified, the method has to
+            accept a single parameter.
+        """
+        if not getattr (self, 'cache_callbacks', None) :
+            self.cache_callbacks = []
+        self.cache_callbacks.append ((method, param))
+
 
 class DetectorError(RuntimeError):
     """ Raised by detectors that want to indicate that something's amiss

Roundup Issue Tracker: http://roundup-tracker.org/