Exemplo n.º 1
0
 def get(self):
     """
     Return a list of all cache keys.
     :return: List[Dict]
     """
     keys = Caches.cache_keys()
     return keys
Exemplo n.º 2
0
    def get(self):
        """
        Setup the program.
        """
        # Reset the database.
        DatabaseService.drop_all()
        DatabaseService.create_all()

        # Setup indexes. Each index init() will drop and re-create.
        Indexes.init()
        self._kibana_settings()

        # Clear all caches.
        Caches.init()

        # Return something so we know it worked.
        return {'message': 'ok'}
Exemplo n.º 3
0
 def post(self, key):
     """
     Populate a cache at a particular key
     :param key: The cache key to populate
     :return: None
     """
     cache = Caches.get_cache(key)
     cache.populate()
Exemplo n.º 4
0
 def delete(self, key):
     """
     Invalidate a cache at a particular key
     :param key: The cache key to invalidate
     :return: None
     """
     cache = Caches.get_cache(key)
     cache.invalidate()
Exemplo n.º 5
0
import pickle
from barbados.caches import Caches
from barbados.caches.base import CacheBase
from barbados.services.cache import CacheService
from barbados.services.logging import LogService
from barbados.objects.ingredienttree import IngredientTree


class IngredientTreeCache(CacheBase):
    """
    Serializing and caching objects is dangerous. But the Treelib
    doesn't have support for loading from JSON yet (only saving to).
    """
    cache_key = 'ingredient_tree_object'

    @classmethod
    def populate(cls):
        CacheService.set(cls.cache_key, pickle.dumps(IngredientTree()))

    @classmethod
    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))


Caches.register_cache(IngredientTreeCache)
Exemplo n.º 6
0
import json
from barbados.caches.base import CacheBase
from barbados.services.cache import CacheService
from barbados.serializers import ObjectSerializer
from barbados.objects.bibliography import Bibliography
from barbados.caches import Caches


class RecipeBibliographyCache(CacheBase):
    """
    Cache a list of all Citations.
    """
    cache_key = 'recipe_bibliography_cache'

    @classmethod
    def populate(cls):
        serialized_citations = [
            ObjectSerializer.serialize(citation, 'dict')
            for citation in Bibliography().citations
        ]
        CacheService.set(cls.cache_key, json.dumps(serialized_citations))


Caches.register_cache(RecipeBibliographyCache)
Exemplo n.º 7
0

class CocktailScanCache(TableScanCache):
    cache_key = 'cocktail_scan_cache'
    model_class = CocktailModel
    factory_class = CocktailFactory


class IngredientScanCache(TableScanCache):
    cache_key = 'ingredient_scan_cache'
    model_class = IngredientModel
    factory_class = IngredientFactory


class MenuScanCache(TableScanCache):
    cache_key = 'menu_scan_cache'
    model_class = MenuModel
    factory_class = MenuFactory


class InventoryScanCache(TableScanCache):
    cache_key = 'inventory_scan_cache'
    model_class = InventoryModel
    factory_class = InventoryFactory


Caches.register_cache(CocktailScanCache)
Caches.register_cache(IngredientScanCache)
Caches.register_cache(MenuScanCache)
Caches.register_cache(InventoryScanCache)
Exemplo n.º 8
0
import json
from barbados.caches.base import CacheBase
from barbados.services.cache import CacheService
from barbados.serializers import ObjectSerializer
from barbados.objects.notebook import Notebook
from barbados.caches import Caches


class NotebookCache(CacheBase):
    """
    Cache a list of all notes.
    """
    cache_key = 'recipe_notebook_cache'

    @classmethod
    def populate(cls):
        serialized_notes = [
            ObjectSerializer.serialize(note, 'dict')
            for note in Notebook().notes
        ]
        CacheService.set(cls.cache_key, json.dumps(serialized_notes))


Caches.register_cache(NotebookCache)