1
# vim: tabstop=4 shiftwidth=4 expandtab
3
A basic driver, used by default in pyblosxom, does not do anything at all
5
class BlosxomCacheBase:
7
Base Class for Caching stories in pyblosxom.
9
A cache is a disposable piece of data that gets updated when an entry is in a
12
Drivers are to subclass this object, overriding methods defined in this class.
13
If there is an error in creating cache data, be as quite as possible, document
14
how a user could check whether his cache works.
16
Driver should expect empty caches and should attempt to create them from
19
@cvar _config: String containing config on where to store the cache. The Value
20
of config is derived from C{py['cacheConfig']} in L{config}.
23
def __init__(self, config):
25
Constructor - setup and load up the cache
27
@param config: String containing config on where to store the cache
33
def load(self, entryid):
35
Try to load up the cache with entryid (a unique key for the entry)
37
@param entryid: The key identifier for your cache
40
self._entryid = entryid # The filename of the entry
41
self._entrydata = {} # The data of the entry
46
Gets the data from the cache, returns a dict or an empty dict.
48
return self._entrydata
53
Returns 0 or 1 based on whether there is cached data, returns 0 is
56
@returns: 0 or 1 based on cache
62
def saveEntry(self, entrydata):
64
Store entrydata in cache
66
@param entrydata: The payload, usually a dict
74
Remove cache entry: This is not used by pyblosxom, but used by
82
Close your cache if necessary.
87
def __getitem__(self, key):
89
Convenience function to make this class look like a dict
92
if not self.has_key(key):
94
return self.getEntry()
97
def __setitem__(self, key, value):
99
Synonymous to L{saveEntry}
102
self.saveEntry(value)
105
def __delitem__(self, key):
110
def has_key(self, key):
112
return self.isCached()
117
List out a list of keys for the cache, to be overridden by a subclass
118
if a full dict interface is required.
123
def get(self, key, default=None):
125
return self.__getitem__(key)
130
class BlosxomCache(BlosxomCacheBase):