summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lib/Bcfg2/Server/Cache.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/lib/Bcfg2/Server/Cache.py b/src/lib/Bcfg2/Server/Cache.py
index d05eb0bf6..b3b906b2c 100644
--- a/src/lib/Bcfg2/Server/Cache.py
+++ b/src/lib/Bcfg2/Server/Cache.py
@@ -96,15 +96,19 @@ class _Cache(MutableMapping):
return len(list(iter(self)))
def expire(self, key=None):
- """ expire all items, or a specific item, from the cache """
+ """ expire all items, or a specific item, from the cache
+
+ :returns: number of expired entries
+ """
+
if key is None:
- expire(*self._tags)
+ return expire(*self._tags)
else:
tags = self._tags | set([key])
# py 2.5 doesn't support mixing *args and explicit keyword
# args
kwargs = dict(exact=True)
- expire(*tags, **kwargs)
+ return expire(*tags, **kwargs)
def __repr__(self):
return repr(dict(self))
@@ -152,7 +156,10 @@ def expire(*tags, **kwargs):
""" Expire all items, a set of items, or one specific item from
the cache. If ``exact`` is set to True, then if the given tag set
doesn't match exactly one item in the cache, nothing will be
- expired. """
+ expired.
+
+ :returns: number of expired entries
+ """
exact = kwargs.pop("exact", False)
count = 0
if not tags:
@@ -170,6 +177,8 @@ def expire(*tags, **kwargs):
for hook in _hooks:
hook(tags, exact, count)
+ return count
+
def add_expire_hook(func):
""" Add a hook that will be called when an item is expired from