Commit 660a4424 authored by Nicolas Delaby's avatar Nicolas Delaby

0s of duration means that cache will never expire

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@27373 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 806ec272
...@@ -49,15 +49,18 @@ class CacheEntry(object): ...@@ -49,15 +49,18 @@ class CacheEntry(object):
def __init__(self, value, cache_duration=None, calculation_time=0): def __init__(self, value, cache_duration=None, calculation_time=0):
self.value = value self.value = value
if cache_duration in (None, 0): if cache_duration in (None, 0):
self.expires_at = None self.expires_at = cache_duration
else: else:
self.expires_at = time.time() + cache_duration self.expires_at = time.time() + cache_duration
self._cache_hit_count = 0 self._cache_hit_count = 0
self.calculation_time = calculation_time self.calculation_time = calculation_time
def isExpired(self): def isExpired(self):
""" check cache entry for expiration """ """check cache entry for expiration
return self.expires_at < time.time() or self.expires_at is None - None means allways expire
- 0 means never expire
"""
return self.expires_at is None or self.expires_at != 0 and self.expires_at < time.time()
def markCacheHit(self, delta=1): def markCacheHit(self, delta=1):
""" mark a read to this cache entry """ """ mark a read to this cache entry """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment