1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

restore old jsonfile behaviour on key expiration

fixes #14456, now it won't expire keys in middle of a play when they
were 'valid' at 'gather time'.
This commit is contained in:
Brian Coca 2016-05-10 15:54:46 -04:00
parent dae1d4dbb7
commit f576082949

View file

@ -62,13 +62,16 @@ class CacheModule(BaseCacheModule):
return None return None
def get(self, key): def get(self, key):
""" This checks the in memory cache first as the fact was not expired at 'gather time'
if self.has_expired(key) or key == "": and it would be problematic if the key did expire after some long running tasks and
raise KeyError user gets 'undefined' error in the same play """
if key in self._cache: if key in self._cache:
return self._cache.get(key) return self._cache.get(key)
if self.has_expired(key) or key == "":
raise KeyError
cachefile = "%s/%s" % (self._cache_dir, key) cachefile = "%s/%s" % (self._cache_dir, key)
try: try:
with codecs.open(cachefile, 'r', encoding='utf-8') as f: with codecs.open(cachefile, 'r', encoding='utf-8') as f: