mirror of https://github.com/zulip/zulip.git
cache: Refactor cache_with_key to use the helper functions.
(imported from commit 24f8af8de17d3376c8ee56da5c2a901c2c314e78)
This commit is contained in:
parent
46c40c011a
commit
d2e18094d8
|
@ -76,14 +76,7 @@ def cache_with_key(keyfunc, cache_name=None, timeout=None, with_statsd_key=None)
|
|||
def func_with_caching(*args, **kwargs):
|
||||
key = KEY_PREFIX + keyfunc(*args, **kwargs)
|
||||
|
||||
memcached_stats_start()
|
||||
if cache_name is None:
|
||||
cache_backend = djcache
|
||||
else:
|
||||
cache_backend = get_cache(cache_name)
|
||||
|
||||
val = cache_backend.get(key)
|
||||
memcached_stats_finish()
|
||||
val = cache_get(key, cache_name=cache_name)
|
||||
|
||||
extra = ""
|
||||
if cache_name == 'database':
|
||||
|
@ -104,9 +97,7 @@ def cache_with_key(keyfunc, cache_name=None, timeout=None, with_statsd_key=None)
|
|||
|
||||
val = func(*args, **kwargs)
|
||||
|
||||
memcached_stats_start()
|
||||
cache_backend.set(key, (val,), timeout=timeout)
|
||||
memcached_stats_finish()
|
||||
cache_set(key, val, cache_name=cache_name, timeout=timeout)
|
||||
|
||||
return val
|
||||
|
||||
|
@ -124,6 +115,16 @@ def cache_set(key, val, cache_name=None, timeout=None):
|
|||
memcached_stats_finish()
|
||||
return ret
|
||||
|
||||
def cache_get(key, cache_name=None):
|
||||
memcached_stats_start()
|
||||
if cache_name is None:
|
||||
cache_backend = djcache
|
||||
else:
|
||||
cache_backend = get_cache(cache_name)
|
||||
ret = cache_backend.get(KEY_PREFIX + key)
|
||||
memcached_stats_finish()
|
||||
return ret
|
||||
|
||||
def cache_get_many(keys, cache_name=None):
|
||||
keys = [KEY_PREFIX + key for key in keys]
|
||||
memcached_stats_start()
|
||||
|
|
Loading…
Reference in New Issue