def retrieve(cls): try: return pickle.loads(CacheService.get(cls.cache_key)) except KeyError: LogService.warning("Attempted to retrieve '%s' but it was empty. Repopulating..." % cls.cache_key) cls.populate() return pickle.loads(CacheService.get(cls.cache_key))
def retrieve(cls): """ Retrieve the cache's value :return: Various """ try: return CacheService.get(cls.cache_key) except KeyError: LogService.warning("Attempted to retrieve '%s' but it was empty. Repopulating..." % cls.cache_key) cls.populate() return CacheService.get(cls.cache_key)
def invalidate(cls): """ Invalidate (delete) the cache value and key. :return: None """ LogService.info("Invalidating cache key %s" % cls.cache_key) return CacheService.delete(cls.cache_key)
def populate(cls): CacheService.set(cls.cache_key, pickle.dumps(IngredientTree()))
def populate(cls): serialized_citations = [ ObjectSerializer.serialize(citation, 'dict') for citation in Bibliography().citations ] CacheService.set(cls.cache_key, json.dumps(serialized_citations))
def populate(cls): serialized_notes = [ ObjectSerializer.serialize(note, 'dict') for note in Notebook().notes ] CacheService.set(cls.cache_key, json.dumps(serialized_notes))
from flask_caching import Cache as FlaskCache from barbados.services.cache import CacheService flask_cache = FlaskCache(config=CacheService.get_flask_config())