Skip to content

Commit

Permalink
Checking if memcached is there before trying to do anything with it.
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlecat committed Jan 12, 2015
1 parent 8781024 commit 6eeca09
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions critiquebrainz/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,14 @@ def invalidate_namespace(namespace):
Args:
namespace: Namespace that needs to be invalidated.
"""
if _mc is None: return
version_key = _glob_namespace + namespace
if _mc.incr(version_key) is None: # namespace isn't initialized
_mc.set(version_key, 1) # initializing the namespace


def _get_namespace_version(namespace):
if _mc is None: return
version_key = _glob_namespace + namespace
version = _mc.get(version_key)
if version is None: # namespace isn't initialized
Expand All @@ -166,6 +168,7 @@ def _get_namespace_version(namespace):

def _prep_key(key, namespace=None):
"""Prepares a key for use with memcached."""
if _mc is None: return
if namespace:
key = "%s:%s:%s" % (namespace, _get_namespace_version(namespace), key)
key = hashlib.sha1(key).hexdigest()
Expand Down

0 comments on commit 6eeca09

Please sign in to comment.