summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTres Seaver <tseaver@palladion.com>2012-07-05 09:00:05 -0400
committerTres Seaver <tseaver@palladion.com>2012-07-05 09:00:05 -0400
commitcc4dd32bab5f8d508c1cd610cff682f0531150b1 (patch)
tree544fc89d6a19f7d0e6c3a58fff0e6face2ec17fc
parentb31f70ccc9983cd89efe54c92d1c3098e2187c1f (diff)
downloadrepoze-lru-cc4dd32bab5f8d508c1cd610cff682f0531150b1.tar.gz
Avoid artificial default.
get() returns None on a miss, which is fine for our purposes.
-rw-r--r--repoze/lru/__init__.py26
1 files changed, 12 insertions, 14 deletions
diff --git a/repoze/lru/__init__.py b/repoze/lru/__init__.py
index 99b32de..c082607 100644
--- a/repoze/lru/__init__.py
+++ b/repoze/lru/__init__.py
@@ -295,8 +295,6 @@ class lru_cache(object):
return lru_cached
-_SENTINEL = _MARKER
-
class CacheMaker(object):
"""Generates decorators that can be cleared later
"""
@@ -307,19 +305,19 @@ class CacheMaker(object):
- timeout : the defaut size for the cache if using expriring cache
"""
- self._maxsize = default.get("maxsize",_SENTINEL)
- self._timeout = default.get("timeout",_DEFAULT_TIMEOUT)
- self._cache = dict()
+ self._maxsize = default.get("maxsize")
+ self._timeout = default.get("timeout")
+ self._cache = {}
def _resolve_setting(self, option):
- name = option.get("name",_SENTINEL)
- maxsize = option.get("maxsize",_SENTINEL)
- maxsize = self._maxsize if maxsize is _SENTINEL else maxsize
- if maxsize is _SENTINEL:
+ name = option.get("name")
+ maxsize = option.get("maxsize")
+ maxsize = self._maxsize if maxsize is None else maxsize
+ if maxsize is None:
raise ValueError("Cache must have a maxsize set")
- timeout = option.get("timeout",_SENTINEL)
- timeout = self._timeout if timeout is _SENTINEL else timeout
- if name is _SENTINEL:
+ timeout = option.get("timeout")
+ timeout = self._timeout if timeout is None else timeout
+ if name is None:
_name= str(uuid.uuid4())
## the probability of collision is so low ....
while _name in self._cache.keys():
@@ -360,11 +358,11 @@ class CacheMaker(object):
)
return lru_cache(option["maxsize"], cache, option["timeout"])
- def clear(self, name=_SENTINEL):
+ def clear(self, name=None):
"""Clear the given cache.
If 'name' is not passed, clear all caches.
"""
- to_clear = self._cache.keys() if name is _SENTINEL else [ name ]
+ to_clear = self._cache.keys() if name is None else [ name ]
for cache_name in to_clear:
self._cache[cache_name].clear()