This software is owned by The university of California, Irvine,
and is not distributed under
any version of the GPL. GPL is a fine series of licenses, but the owners of the software need it to be distributed under these terms.
cachedb is a dictionary-like database wrapper that can greatly improve the
performance of some kinds of database operation. Beyond allowing write-through
and write-back element caching, the module also allows you to specific
disk-to-core (from_string) and core-to-disk (to_string) transparent conversion
functions that will only be used as little as possible.
IOW, if you read an item off of disk, it will transparently be converted to an
in-core representation. If you change it, and the cache isn't overflowing, the
new version won't be re-converted back to the disk format or written to disk
until later.
The initialization method looks like:
def __init__(self, \
databasefile, \
databasetype, \
databasemode, \
to_string=None, \
from_string=None, \
max_elements_in_memory=10000, \
read_use=True, \
write_use=True, \
write_through=True, \
too_many_percent=95.0, \
verbose=False):
...and the rest is just like using a dictionary - with
the exception that if you use a write-back cache, you'll need to use the
dict.close() method to flush the dirty buffers.
Download it here
Related modules:
- A list of persistent storage modules for python
- The most similar to cachedb.py appears to be shelve.py.
- SImilarities:
- Both give the appearance of storing arbitrary objects in a disk-based database via the usual dict[key], dict[key] = value, dict.keys(),
del dict[key] and so forth, after the dict has been created.
- Both implement caching
- Neither shelve.py nor cachedb.py will transparently convert your keys to strings - they both only convert the values under those
keys to strings transparently.
- Differences:
- It appears that while cachedb.py requires you to specify "object to string" and "string to object" conversion functions at database
creation time, shelve.py attempts to (and usually succeeds in) use the pickling that comes with python.
- It appears that if you use a writeback version of shelve.py, then it will attempt to cache all used items in memory, while
cachedb.py allows you to specify how many items to cache and how often to flush the least recently used items from the cache.
- shelve.py has a sync() method, while until today (Fri Feb 17 11:15:59 PST 2006), cachedb.py had a flush() method.
However, cachedb.py now has sync() as a synonym for flush().
- Assume that you have a shelve or cachedb and the values stored in them are lists of numbers. The means of appending a number to the
list differs.
- With shelve.py, you would:
- list = shelf[key]
- list.append(1)
- shelf[key] = list
- While with cachedb.py you would: