Add memcached caching for get_stream lookups.

(imported from commit a089c8a99eaa1fa28ce401859cac1bdf0eb92a69)
This commit is contained in:
Tim Abbott
2013-03-18 11:40:00 -04:00
parent 9c2a9eb288
commit 3c143db01a

View File

@@ -172,7 +172,15 @@ def get_client(name):
return Client.objects.get(name=name)
return client
def get_stream_cache_key(stream_name, realm):
if isinstance(realm, Realm):
realm_id = realm.id
else:
realm_id = realm
return "stream_by_realm_and_name:%s:%s" % (realm_id, hashlib.sha1(stream_name.strip().lower()).hexdigest())
# get_stream takes either a realm id or a realm
@cache_with_key(get_stream_cache_key)
def get_stream(stream_name, realm):
if isinstance(realm, Realm):
realm_id = realm.id