diff options
author | Sol Jerome <sol.jerome@gmail.com> | 2017-08-31 08:18:47 -0500 |
---|---|---|
committer | Sol Jerome <sol.jerome@gmail.com> | 2017-08-31 08:18:47 -0500 |
commit | a0eeab0912fcfb72aa57fa9a6f612e8c6f3234ba (patch) | |
tree | 3faffdfa560526c299fdebeaf1368a0b2dc20924 /src/lib/Bcfg2/Server/Cache.py | |
parent | e193079d1779e4d66d80882e6f1c3ff9ba05619b (diff) | |
parent | 0985c2aed06c14d8b79805d21449f2f1d31dd20c (diff) | |
download | bcfg2-a0eeab0912fcfb72aa57fa9a6f612e8c6f3234ba.tar.gz bcfg2-a0eeab0912fcfb72aa57fa9a6f612e8c6f3234ba.tar.bz2 bcfg2-a0eeab0912fcfb72aa57fa9a6f612e8c6f3234ba.zip |
Merge branch 'feature/ldap-enhancements' of https://github.com/AlexanderS/bcfg2
Diffstat (limited to 'src/lib/Bcfg2/Server/Cache.py')
-rw-r--r-- | src/lib/Bcfg2/Server/Cache.py | 17 |
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 |