Skip to content

Commit a0951c3

Browse files
committed
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.
1 parent f55e509 commit a0951c3

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

CHANGES.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ Entries without name were done by Richard Jones.
77

88
Features:
99

10-
- ...
10+
- Add an interface to register clearCache callbacks in roundupdb.
11+
Sometimes complicated computations may require an application cache.
12+
This application can now register a callback to clear the application
13+
cache, because roundup knows better when to clear it (usually when a
14+
transaction ends, either with rollback or with commit). The interface
15+
for this is currently considered experimental. The current interface
16+
is registerClearCacheCallback(self, method, param) where method is
17+
called with param as the only parameter. (Ralf Schlatterbeck)
1118

1219
Fixed:
1320

roundup/backends/back_anydbm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,8 @@ def clearCache(self):
733733
self.newnodes = {}
734734
self.destroyednodes = {}
735735
self.transactions = []
736+
# upcall is necessary!
737+
roundupdb.Database.clearCache(self)
736738

737739
def getCachedClassDB(self, classname):
738740
""" get the class db, looking in our cache of databases for commit

roundup/backends/rdbms_common.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ def __init__(self, config, journaltag=None):
195195
def clearCache(self):
196196
self.cache = {}
197197
self.cache_lru = []
198+
# upcall is necessary!
199+
roundupdb.Database.clearCache(self)
198200

199201
def getSessionManager(self):
200202
return Sessions(self)

roundup/roundupdb.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,26 @@ def get_logger(self):
149149

150150
return self.__logger
151151

152+
def clearCache(self):
153+
""" Backends may keep a cache.
154+
It must be cleared at end of commit and rollback methods.
155+
We allow to register user-defined cache-clearing routines
156+
that are called by this routine.
157+
"""
158+
if getattr (self, 'cache_callbacks', None) :
159+
for method, param in self.cache_callbacks:
160+
method(param)
161+
162+
def registerClearCacheCallback(self, method, param = None):
163+
""" Register a callback method for clearing the cache.
164+
It is called with the given param as the only parameter.
165+
Even if the parameter is not specified, the method has to
166+
accept a single parameter.
167+
"""
168+
if not getattr (self, 'cache_callbacks', None) :
169+
self.cache_callbacks = []
170+
self.cache_callbacks.append ((method, param))
171+
152172

153173
class DetectorError(RuntimeError):
154174
""" Raised by detectors that want to indicate that something's amiss

0 commit comments

Comments
 (0)