Created
April 12, 2012 06:59
-
-
Save samtardif/2365290 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def cache_method(name): | |
def dict_cache_wrapper(fn): | |
cache = {} | |
def wrapper(*args): | |
if args not in cache: | |
cache[args] = fn(*args) | |
return cache[args] | |
return wrapper | |
def memcached_wrapper(fn): | |
def wrapper(*args): | |
return fn(*args) | |
return wrapper | |
if name == 'memory': | |
return dict_cache_wrapper | |
elif name == 'memcached': | |
return memcached_wrapper | |
else: | |
raise Exception | |
@cache_method("memory") | |
def lookup(key): | |
return key | |
lookup("hello") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment