import hashlib
import json
import memcache

class Cache(object):
	"""Wrapper around a singleton memcache client."""

	client = memcache.Client(['127.0.0.1:11211'], debug=0)

	@classmethod
	def call(cls, func, *args, **kwargs):
		call_dump = json.dumps([func.__module__, func.__name__, args, kwargs])
		memcache_key = 'pluss--%s' % hashlib.md5(call_dump).hexdigest()
		result = cls.client.get(memcache_key)
		if not result:
			result = func(*args, **kwargs)
			cls.client.set(memcache_key, result)
		return result

	@classmethod
	def get(cls, *args, **kwargs):
		return cls.client.get(*args, **kwargs)

	@classmethod
	def set(cls, *args, **kwargs):
		return cls.client.set(*args, **kwargs)

	@classmethod
	def delete(cls, *args, **kwargs):
		return cls.client.delete(*args, **kwargs)

	@classmethod
	def incr(cls, *args, **kwargs):
		return cls.client.incr(*args, **kwargs)

	@classmethod
	def decr(cls, *args, **kwargs):
		return cls.client.decr(*args, **kwargs)

@@ -20,16 +20,22 @@
 rt json%0A
+try:%0A%09
 import m
@@ -46,77 +46,358 @@
 che%0A
-%0Aclass Cache(object):%0A%09%22%22%22Wrapper around a singleton memcache client.
+%09_hush_pyflakes = (memcache,)%0A%09del _hush_pyflakes%0Aexcept ImportError:%0A%09memcache = None%0A%0Aclass Cache(object):%0A%09%22%22%22Wrapper around a singleton memcache client.%0A%0A%09Note: If the 'memcache' library is not available,%0A%09this wrapper will do nothing - call() will transparently%0A%09always call the provided function, and everything else%0A%09will simply return None.%0A%09
 %22%22%22%0A
@@ -406,16 +406,29 @@
 client =
+ memcache and
  memcach
@@ -520,16 +520,70 @@
 wargs):%0A
+%09%09if not cls.client:%0A%09%09%09return func(*args, **kwargs)%0A%0A
 %09%09call_d
@@ -908,32 +908,47 @@
 args):%0A%09%09return 
+cls.client and 
 cls.client.get(*
@@ -1011,32 +1011,47 @@
 args):%0A%09%09return 
+cls.client and 
 cls.client.set(*
@@ -1117,32 +1117,47 @@
 args):%0A%09%09return 
+cls.client and 
 cls.client.delet
@@ -1224,32 +1224,47 @@
 args):%0A%09%09return 
+cls.client and 
 cls.client.incr(
@@ -1329,32 +1329,47 @@
 args):%0A%09%09return 
+cls.client and 
 cls.client.decr(

Make memcached integration optional.