25 lines
634 B
Python
25 lines
634 B
Python
from cache.Cache import Cache
|
|
from core.global_symbols import NotFound, Removed
|
|
|
|
|
|
class IncCache(Cache):
|
|
"""
|
|
Increment the value of the key every time it's accessed
|
|
"""
|
|
|
|
def _get(self, key, alt_sdp=None):
|
|
value = super()._get(key, alt_sdp=alt_sdp)
|
|
if value in (NotFound, Removed):
|
|
value = 0
|
|
value += 1
|
|
self._put(key, value, alt_sdp)
|
|
return value
|
|
|
|
def _put(self, key, value, alt_sdp):
|
|
self._cache[key] = value
|
|
self._add_to_add(key)
|
|
return True
|
|
|
|
def _alt_get(self, key):
|
|
return super()._get(key) # point to parent, not to self
|