Пример #1
0
 def __init__(self, *args, **kwargs):
     redis = get_cache_redis()
     if redis is None:
         self.cache = _Cache(*args, **kwargs)
     else:
         assert Redis is not None, 'Packages needed by Redis are missing'
         self.cache = Redis(*args, **kwargs)
Пример #2
0
class Cache(object):
    # AKE: this class wraps technical holders and manage serialization
    def __init__(self, *args, **kwargs):
        redis = get_cache_redis()
        if redis is None:
            self.cache = _Cache(*args, **kwargs)
        else:
            assert Redis is not None, 'Packages needed by Redis are missing'
            self.cache = Redis(*args, **kwargs)

    def get(self, key, default=None):
        result = self.cache.get(key, Default)
        if result is Default:
            return default
        else:
            return msgpack.unpackb(result, encoding='utf-8',
                object_hook=decode_hook)

    def set(self, key, value):
        value = msgpack.packb(value, use_bin_type=True, default=encode_hook)
        self.cache.set(key, value)

    def clear(self):
        self.cache.clear()

    @staticmethod
    def clean(dbname):
        _Cache.clean(dbname)
        if Redis is not None:
            Redis.clean(dbname)

    @staticmethod
    def resets(dbname):
        _Cache.resets(dbname)
        if Redis is not None:
            Redis.resets(dbname)

    @staticmethod
    def drop(dbname):
        _Cache.drop(dbname)
        if Redis is not None:
            Redis.drop(dbname)
Пример #3
0
 def drop(dbname):
     _Cache.drop(dbname)
     if Redis is not None:
         Redis.drop(dbname)
Пример #4
0
 def resets(dbname):
     _Cache.resets(dbname)
     if Redis is not None:
         Redis.resets(dbname)
Пример #5
0
 def clean(dbname):
     _Cache.clean(dbname)
     if Redis is not None:
         Redis.clean(dbname)