Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"default": {
"cache": "aiocache.RedisCache",
"endpoint": "127.0.0.10",
"port": 6378,
"serializer": {"class": "aiocache.serializers.PickleSerializer"},
"plugins": [
{"class": "aiocache.plugins.HitMissRatioPlugin"},
{"class": "aiocache.plugins.TimingPlugin"},
],
},
"alt": {"cache": "aiocache.SimpleMemoryCache"},
}
)
default = caches.get("default")
alt = caches.get("alt")
assert isinstance(default, RedisCache)
assert default.endpoint == "127.0.0.10"
assert default.port == 6378
assert isinstance(default.serializer, PickleSerializer)
assert len(default.plugins) == 2
assert isinstance(alt, SimpleMemoryCache)
{
"default": {
"cache": "aiocache.RedisCache",
"endpoint": "127.0.0.10",
"port": 6378,
"serializer": {"class": "aiocache.serializers.PickleSerializer"},
"plugins": [
{"class": "aiocache.plugins.HitMissRatioPlugin"},
{"class": "aiocache.plugins.TimingPlugin"},
],
},
"alt": {"cache": "aiocache.SimpleMemoryCache"},
}
)
default = caches.get("default")
alt = caches.get("alt")
assert isinstance(default, RedisCache)
assert default.endpoint == "127.0.0.10"
assert default.port == 6378
assert isinstance(default.serializer, PickleSerializer)
assert len(default.plugins) == 2
assert isinstance(alt, SimpleMemoryCache)
"endpoint": "127.0.0.10",
"port": 6378,
"ttl": 10,
"serializer": {
"class": "aiocache.serializers.PickleSerializer",
"encoding": "encoding",
},
"plugins": [
{"class": "aiocache.plugins.HitMissRatioPlugin"},
{"class": "aiocache.plugins.TimingPlugin"},
],
}
}
)
cache = caches.get("default")
assert isinstance(cache, RedisCache)
assert cache.endpoint == "127.0.0.10"
assert cache.port == 6378
assert cache.ttl == 10
assert isinstance(cache.serializer, PickleSerializer)
assert cache.serializer.encoding == "encoding"
assert len(cache.plugins) == 2
def get_cache(namespace=None):
if namespace is None:
return aiocache.caches.get('default')
try:
return aiocache.caches.get(namespace)
except KeyError:
pass
_cache_config = aiocache.caches.get_alias_config('default')
base_namespace = _cache_config['namespace']
if not base_namespace:
actual_namespace = namespace
else:
actual_namespace = '_'.join((base_namespace, namespace))
_cache_config['namespace'] = actual_namespace
aiocache.caches.add(namespace, _cache_config)
return aiocache.caches.get(namespace)