# # # patch "README" # from [1c7c6accbc0fca7adb5751504b36a252b110fefa] # to [26bd70117a1ed757aa23d0df7930e3f65e8ff207] # # patch "tracvc/mtn/cache.py" # from [4a30ff0444dffafb15cdab7d65908b41b99692fd] # to [bc5c1e4f78fff49ac37e54464d7a7ead8b268037] # ============================================================ --- README 1c7c6accbc0fca7adb5751504b36a252b110fefa +++ README 26bd70117a1ed757aa23d0df7930e3f65e8ff207 @@ -46,14 +46,18 @@ * The full path to the Monotone binary can be specified using the 'mtn_binary' option. - * A caching method for Monotone manifests, certs and changesets can - be specified using the 'cachespec' option. The format is: - cachespec = backend[:opt1[:opt2[...]]] - Currently two backends are provided: + * A caching method for Monotone manifests, certs, changesets, + etc. can be specified using the 'cachespec' option. The format is: + cachespec = backend[:option1[:option2[...]]] + + Currently these backends are provided: - 'localmem': (default) uses local memory for caching. Takes no - options. + options. - 'dbmshelve:prefix': Persistent, uses Unix DBM databases named - prefix*.{pag|dir}. All directories in prefix must exist. + prefix*.{pag|dir}. All directories in prefix must exist. Not suited + for concurrent access by more than one process. + - 'bsddb:dir:prefix': Uses the bsddb3 binding to a persistent + BerkeleyDB database. The directory 'dir' must be writable by trac. Known Problems/Missing Features ============================================================ --- tracvc/mtn/cache.py 4a30ff0444dffafb15cdab7d65908b41b99692fd +++ tracvc/mtn/cache.py bc5c1e4f78fff49ac37e54464d7a7ead8b268037 @@ -26,8 +26,6 @@ from threading import Lock except ImportError: from dummy_threading import Lock -from shelve import Shelf -import dbm class Cache(object): @@ -151,9 +149,12 @@ """Using Python's shelve on a DBM database.""" def __init__(self, realm, prefix): - LocalMem.__init__(self, realm) + import shelve + import dbm + self.dbname = prefix + realm - self.cache = Shelf(dbm.open(self.dbname, 'c')) + self.cache = shelve.Shelf(dbm.open(self.dbname, 'c')) + self.lock = Lock() def __del__(self): self.cache.close() @@ -164,6 +165,38 @@ Cache.add_backend('dbmshelve', DBMShelve) +class BSDDBShelve(Cache): + """Using the bsddb3 interface to db.""" + + dbenv = None + + @classmethod + def get_env(self, dir): + if not self.dbenv: + from bsddb3 import db + self.dbenv = db.DBEnv() + self.dbenv.open(dir, + db.DB_INIT_CDB|db.DB_INIT_MPOOL|db.DB_CREATE) + return self.dbenv + + def __init__(self, realm, dir, prefix=''): + from bsddb3 import dbshelve + self.dbname = prefix + realm + self.cache = dbshelve.open(self.dbname, dbenv=self.get_env(dir)) + + def set(self, key, value): + self.cache[key] = value + + def add(self, key, value): + # FIXME wrong semantics + self.cache[key] = value + + def get(self, key): + return self.cache[key] + +Cache.add_backend('bsddb', BSDDBShelve) + + def memoize(get_cachespec, realm = None): """Decorates a method with the Memoize decorator. get_cachespec is a method of the same class which returns the desired cachespec, @@ -174,7 +207,7 @@ class Memoize(object): """Caches return values of the decorated method.""" - def __init__(self, function, get_cachespec, realm = None): + def __init__(self, function, get_cachespec, realm): self.function = function self.get_cachespec = get_cachespec self.realm = realm or function.__name__