CacheRegion.py (cheetah3-3.1.0) | : | CacheRegion.py (cheetah3-3.2.0) | ||
---|---|---|---|---|
skipping to change at line 79 | skipping to change at line 79 | |||
def clear(self): | def clear(self): | |||
self._cacheStore.delete(self._cacheItemID) | self._cacheStore.delete(self._cacheItemID) | |||
self._refreshTime = None | self._refreshTime = None | |||
class _CacheDataStoreWrapper(object): | class _CacheDataStoreWrapper(object): | |||
def __init__(self, dataStore, keyPrefix): | def __init__(self, dataStore, keyPrefix): | |||
self._dataStore = dataStore | self._dataStore = dataStore | |||
self._keyPrefix = keyPrefix | self._keyPrefix = keyPrefix | |||
def get(self, key): | def get(self, key): | |||
return self._dataStore.get(self._keyPrefix+key) | return self._dataStore.get(self._keyPrefix + key) | |||
def delete(self, key): | def delete(self, key): | |||
self._dataStore.delete(self._keyPrefix+key) | self._dataStore.delete(self._keyPrefix + key) | |||
def set(self, key, val, time=0): | def set(self, key, val, time=0): | |||
self._dataStore.set(self._keyPrefix+key, val, time=time) | self._dataStore.set(self._keyPrefix + key, val, time=time) | |||
class CacheRegion(object): | class CacheRegion(object): | |||
''' | ''' | |||
A `CacheRegion` stores some `CacheItem` instances. | A `CacheRegion` stores some `CacheItem` instances. | |||
This implementation stores the data in the memory of the current process. | This implementation stores the data in the memory of the current process. | |||
If you need a more advanced data store, create a cacheStore class that | If you need a more advanced data store, create a cacheStore class that | |||
works with Cheetah's CacheStore protocol and provide it as the cacheStore | works with Cheetah's CacheStore protocol and provide it as the cacheStore | |||
argument to __init__. For example you could use | argument to __init__. For example you could use | |||
Cheetah.CacheStore.MemcachedCacheStore, a wrapper around the Python | Cheetah.CacheStore.MemcachedCacheStore, a wrapper around the Python | |||
skipping to change at line 108 | skipping to change at line 108 | |||
_cacheItemClass = CacheItem | _cacheItemClass = CacheItem | |||
def __init__(self, regionID, templateCacheIdPrefix='', cacheStore=None): | def __init__(self, regionID, templateCacheIdPrefix='', cacheStore=None): | |||
self._isNew = True | self._isNew = True | |||
self._regionID = regionID | self._regionID = regionID | |||
self._templateCacheIdPrefix = templateCacheIdPrefix | self._templateCacheIdPrefix = templateCacheIdPrefix | |||
if not cacheStore: | if not cacheStore: | |||
cacheStore = Cheetah.CacheStore.MemoryCacheStore() | cacheStore = Cheetah.CacheStore.MemoryCacheStore() | |||
self._cacheStore = cacheStore | self._cacheStore = cacheStore | |||
self._wrappedCacheDataStore = _CacheDataStoreWrapper( | self._wrappedCacheDataStore = _CacheDataStoreWrapper( | |||
cacheStore, keyPrefix=templateCacheIdPrefix+':'+regionID+':') | cacheStore, keyPrefix=templateCacheIdPrefix + ':' + regionID + ':') | |||
self._cacheItems = {} | self._cacheItems = {} | |||
def isNew(self): | def isNew(self): | |||
return self._isNew | return self._isNew | |||
def clear(self): | def clear(self): | |||
" drop all the caches stored in this cache region " | " drop all the caches stored in this cache region " | |||
for cacheItemId in list(self._cacheItems.keys()): | for cacheItemId in list(self._cacheItems.keys()): | |||
cacheItem = self._cacheItems[cacheItemId] | cacheItem = self._cacheItems[cacheItemId] | |||
cacheItem.clear() | cacheItem.clear() | |||
End of changes. 4 change blocks. | ||||
4 lines changed or deleted | 4 lines changed or added |