Esempio n. 1
0
def redis_py(client,
             key_prefix=None,
             expire=None,
             coder=None,
             ignorable_keys=None,
             interface=CacheInterface,
             storage_implementation=RedisImplementation):

    return fbase.factory(client,
                         key_prefix=key_prefix,
                         wrapper_class=wrapper_class,
                         interface=interface,
                         storage_implementation=storage_implementation,
                         miss_value=None,
                         expire_default=expire,
                         coder=coder,
                         ignorable_keys=ignorable_keys)
Esempio n. 2
0
def dict(obj,
         key_prefix='',
         expire=None,
         coder=None,
         ignorable_keys=None,
         interface=CacheInterface,
         storage_implementation=DictImpl):

    return fbase.factory(obj,
                         key_prefix=key_prefix,
                         wrapper_class=wrapper_class,
                         interface=interface,
                         storage_implementation=storage_implementation,
                         miss_value=None,
                         expire_default=expire,
                         coder=coder,
                         ignorable_keys=ignorable_keys)
Esempio n. 3
0
def doublecache(client,
                key_prefix,
                time=0,
                coder=None,
                ignorable_keys=None,
                interface=DoubleCacheInterface):
    from ring.func_asyncio import DictImpl

    return factory(client,
                   key_prefix=key_prefix,
                   wrapper_class=wrapper_class,
                   interface=interface,
                   storage_implementation=DictImpl,
                   miss_value=None,
                   expire_default=time,
                   coder=coder,
                   ignorable_keys=ignorable_keys)
Esempio n. 4
0
def arcus(client,
          key_prefix=None,
          time=0,
          coder=None,
          ignorable_keys=None,
          interface=CacheInterface):
    class Impl(fbase.Storage):
        def get_value(self, client, key):
            value = client.get(key).get_result()
            if value is None:
                raise fbase.NotFound
            return value

        def set_value(self, client, key, value):
            client.set(key, value, time)

        def del_value(self, client, key):
            client.delete(key)

        def touch_value(self, client, key, expire=time):
            client.touch(key, expire)

    rule = re.compile(r'[!-~]+')

    def key_refactor(key):
        if len(key) < 250 and rule.match(key).group(0) == key:
            return key
        try:
            hashed = hashlib.sha1(key).hexdigest()
        except TypeError:
            # FIXME: ensure key is bytes before key_refactor
            key = key.encode('utf-8')
            hashed = hashlib.sha1(key).hexdigest()
        return 'ring-sha1:' + hashed

    return fbase.factory(client,
                         key_prefix=key_prefix,
                         wrapper_class=wrapper_class,
                         interface=interface,
                         storage_implementation=Impl,
                         miss_value=None,
                         expire_default=time,
                         coder=coder,
                         ignorable_keys=ignorable_keys,
                         key_refactor=key_refactor)
Esempio n. 5
0
def memcache(client,
             key_prefix=None,
             time=0,
             coder=None,
             ignorable_keys=None,
             interface=CacheInterface,
             storage_implementation=MemcacheImpl):
    from ring._memcache import key_refactor
    miss_value = None

    return fbase.factory(client,
                         key_prefix=key_prefix,
                         wrapper_class=wrapper_class,
                         interface=interface,
                         storage_implementation=storage_implementation,
                         miss_value=miss_value,
                         expire_default=time,
                         coder=coder,
                         ignorable_keys=ignorable_keys,
                         key_refactor=key_refactor)