1
2
3
4
5
6
7
8
9
10
11 """
12 The cache base class. Subclasses of this class provide caching for
13 blog entry data in PyBlosxom.
14 """
15
16 __revision__ = "$Revision: 913 $"
17
19 """
20 Base Class for Caching stories in pyblosxom.
21
22 A cache is a disposable piece of data that gets updated when an entry
23 is in a fresh state.
24
25 Drivers are to subclass this object, overriding methods defined in
26 this class. If there is an error in creating cache data, be as quite
27 as possible, document how a user could check whether his cache works.
28
29 Driver should expect empty caches and should attempt to create them from
30 scratch.
31
32 @ivar _config: String containing config on where to store the cache.
33 The value of config is derived from C{py['cacheConfig']} in config.py.
34 @type _config: string
35 """
37 """
38 Constructor - setup and load up the cache
39
40 @param req: the request object
41 @type req: Request
42
43 @param config: String containing config on where to store the cache
44 @type config: string
45 """
46 self._request = req
47 self._config = config
48
49 self._entryid = ""
50 self._entrydata = {}
51
52 - def load(self, entryid):
53 """
54 Try to load up the cache with entryid (a unique key for the entry)
55
56 @param entryid: The key identifier for your cache
57 @type entryid: string
58 """
59 self._entryid = entryid
60 self._entrydata = {}
61
63 """
64 Gets the data from the cache, returns a dict or an empty dict.
65 """
66 return self._entrydata
67
69 """
70 Returns 0 or 1 based on whether there is cached data, returns 0 is
71 cache data is stale
72
73 @returns: 0 or 1 based on cache
74 @rtype: boolean
75 """
76 return 0
77
78 - def saveEntry(self, entrydata):
79 """
80 Store entrydata in cache
81
82 @param entrydata: The payload, usually a dict
83 @type entrydata: dict
84 """
85 pass
86
88 """
89 Remove cache entry: This is not used by pyblosxom, but used by
90 utilities.
91 """
92 pass
93
95 """
96 Override this to close your cache if necessary.
97 """
98 pass
99
101 """
102 Convenience function to make this class look like a dict.
103 """
104 self.load(key)
105 if not self.has_key(key):
106 raise KeyError
107 return self.getEntry()
108
110 """
111 Synonymous to L{saveEntry}
112 """
113 self.load(key)
114 self.saveEntry(value)
115
117 """
118 Convenience function to make this look more like a dict.
119 """
120 self.load(key)
121 self.rmEntry()
122
124 """
125 Convenience function to make this look more like a dict.
126 """
127 self.load(key)
128 return self.isCached()
129
131 """
132 List out a list of keys for the cache, to be overridden by a subclass
133 if a full dict interface is required.
134 """
135 return []
136
137 - def get(self, key, default=None):
138 """
139 Convenience function to make this look more like a dict.
140 """
141 try:
142 return self.__getitem__(key)
143 except KeyError:
144 return default
145
146
148 """
149 A null cache.
150 """
151 pass
152
153
154