1
2
3
4
5
6
7
8
9
10
11 """
12 This cache driver creates shelved data as cache in a dbm file.
13
14 To use this driver, add the following configuration options in your config.py
15
16 py['cacheDriver'] = 'entryshelve'
17 py['cacheConfig'] = '/path/to/a/cache/dbm/file'
18
19 If successful, you will see the cache file. Be sure that you have write access
20 to the cache file.
21 """
22
23 __revision__ = "$Revision: 913 $"
24
25 from Pyblosxom.cache.base import BlosxomCacheBase
26 import shelve
27 import os
28
30 """
31 This stores entries in shelves in a .dbm file.
32 """
34 """
35 Initializes BlosxomCacheBase.__init__ and also opens the
36 shelf file.
37 """
38 BlosxomCacheBase.__init__(self, req, config)
39 self._db = shelve.open(self._config)
40
41 - def load(self, entryid):
46
48 """
49 Get an entry from the shelf.
50 """
51 data = self._db.get(self._entryid, {})
52 return data.get('entrydata', {})
53
55 """
56 Returns true if the entry is cached and the cached version is
57 not stale. Returns false otherwise.
58 """
59 data = self._db.get(self._entryid, {'mtime':0})
60 if os.path.isfile(self._entryid):
61 return data['mtime'] == os.stat(self._entryid)[8]
62 else:
63 return None
64
65
66 - def saveEntry(self, entrydata):
67 """
68 Save data in the pickled file.
69 """
70 payload = {}
71 payload['mtime'] = os.stat(self._entryid)[8]
72 payload['entrydata'] = entrydata
73
74 self._db[self._entryid] = payload
75
76
78 """
79 Removes an entry from the shelf.
80 """
81 if self._db.has_key(self._entryid):
82 del self._db[self._entryid]
83
85 """
86 Returns a list of entries that are cached in the shelf.
87
88 @returns: list of entry paths
89 @rtype: list of strings
90 """
91 ret = []
92 for key in self._db.keys():
93 self.load(key)
94 if self.isCached():
95 ret.append(key)
96 else:
97
98 del self._db[self._entryid]
99 return ret
100
101
103 """
104 Closes the db file.
105 """
106 self._db.close()
107 self._db = None
108
109
110