async def get(self, key: str, default: Any = None, fail: bool = False) -> Any: key = str(key) c = self.__CACHE if key in c: log.debug('Cache key "%s" found in __CACHE. Checking expiry...', key) vc = c[key] if str(vc['timeout'] ) != 'never' and vc['timeout'] < datetime.utcnow(): log.debug('Cache key "%s" has expired. Removing from cache.') del c[key] if fail: raise CacheNotFound(f'Cache key "{key}" was expired.') return default log.debug( 'Cache key "%s" is valid and not expired. Returning value "%s"', key, vc) return vc['value'] if fail: raise CacheNotFound(f'Cache key "{key}" was not found.') log.debug( 'Cache key "%s" was not found in __CACHE. Returning default value.', key) return default
def get(self, key: str, default: Any = None, fail: bool = False) -> Any: key = str(key) res = self.redis.get(key) if empty(res): if fail: raise CacheNotFound(f'Cache key "{key}" was not found.') return default return pickle.loads(res) if self.use_pickle else res
def get(self, key: Union[bytes, str], default: Any = None, fail: bool = False) -> Any: key = str(stringify(key)) res = self.mcache.get(key) if empty(res): if fail: raise CacheNotFound(f'Cache key "{key}" was not found.') return default return pickle.loads(res) if self.use_pickle else res
def get(self, key: str, default: Any = None, fail: bool = False, _auto_purge=True) -> Any: key = str(key) _not_found_msg = f'Cache key "{key}" was not found.' if _auto_purge: self.purge_expired() res = self.wrapper.find_cache_key(key) if _cache_result_expired(res, _auto_purge=_auto_purge): log.debug( "Caller attempted to retrieve expired key '%s', but _auto_purge is True - auto-removing expired key %s", key, key) self.remove(key) res = None _not_found_msg += ' (key was expired - auto-removed)' if empty(res): if fail: raise CacheNotFound(_not_found_msg) return default return pickle.loads(res.value) if self.use_pickle else res.value