69 """ |
69 """ |
70 Add delta to value in the cache. If the key does not exist, raise a |
70 Add delta to value in the cache. If the key does not exist, raise a |
71 ValueError exception. |
71 ValueError exception. |
72 """ |
72 """ |
73 if key not in self: |
73 if key not in self: |
74 raise ValueError, "Key '%s' not found" % key |
74 raise ValueError("Key '%s' not found" % key) |
75 new_value = self.get(key) + delta |
75 new_value = self.get(key) + delta |
76 self.set(key, new_value) |
76 self.set(key, new_value) |
77 return new_value |
77 return new_value |
78 |
78 |
79 def decr(self, key, delta=1): |
79 def decr(self, key, delta=1): |
89 """ |
89 """ |
90 # This is a separate method, rather than just a copy of has_key(), |
90 # This is a separate method, rather than just a copy of has_key(), |
91 # so that it always has the same functionality as has_key(), even |
91 # so that it always has the same functionality as has_key(), even |
92 # if a subclass overrides it. |
92 # if a subclass overrides it. |
93 return self.has_key(key) |
93 return self.has_key(key) |
|
94 |
|
95 def set_many(self, data, timeout=None): |
|
96 """ |
|
97 Set a bunch of values in the cache at once from a dict of key/value |
|
98 pairs. For certain backends (memcached), this is much more efficient |
|
99 than calling set() multiple times. |
|
100 |
|
101 If timeout is given, that timeout will be used for the key; otherwise |
|
102 the default cache timeout will be used. |
|
103 """ |
|
104 for key, value in data.items(): |
|
105 self.set(key, value, timeout) |
|
106 |
|
107 def delete_many(self, keys): |
|
108 """ |
|
109 Set a bunch of values in the cache at once. For certain backends |
|
110 (memcached), this is much more efficient than calling delete() multiple |
|
111 times. |
|
112 """ |
|
113 for key in keys: |
|
114 self.delete(key) |
|
115 |
|
116 def clear(self): |
|
117 """Remove *all* values from the cache at once.""" |
|
118 raise NotImplementedError |