Add a bunch of statsd logging

(imported from commit 8c17a76fed08c34abab3cc45d76a0fb30774d73a)
This commit is contained in:
Leo Franchi
2013-04-16 16:58:21 -04:00
parent 46415d4984
commit 652b821d64
5 changed files with 53 additions and 8 deletions

View File

@@ -5,6 +5,8 @@ from django.core.cache import get_cache
from utils import make_safe_digest
from zephyr.lib.utils import statsd, statsd_key
def cache_with_key(keyfunc, cache_name=None, timeout=None):
"""Decorator which applies Django caching to a function.
@@ -24,6 +26,11 @@ def cache_with_key(keyfunc, cache_name=None, timeout=None):
key = keyfunc(*args, **kwargs)
val = cache_backend.get(key)
if val is not None:
statsd.incr("cache.%s.hit" % (statsd_key(key),))
else:
statsd.incr("cache.%s.miss" % (statsd_key(key),))
# Values are singleton tuples so that we can distinguish
# a result of None from a missing key.
if val is not None: