Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @cacheable('/path/to/cache/file')
- def my_function(a, b, c):
- return 'something'
- def decorator(f):
- def decorated(*args,**kwargs):
- cache = Cache(cachepath)
- if cache.iscached(*args,**kwargs):
- ...
- else:
- res = f(*args,**kwargs)
- cache.store((*args,**kwargs), res)
- return res
- return decorated
- def cache(filepath)
- def decorator(f):
- def decorated(*args,**kwargs):
- cache = Cache(cachepath)
- if cache.iscached(*args,**kwargs):
- ...
- else:
- res = f(*args,**kwargs)
- cache.store((*args,**kwargs), res)
- return res
- return decorated
- return decorator
- def mydecorator(func):
- def wrapper(*args, **kwargs):
- return func(*args, **kwargs)
- return wrapper
- @mydecorator
- def foo(a, b, c):
- pass
- def addint(val):
- def decorator(func):
- def wrapped(*args, **kwargs):
- result = func(*args, **kwargs)
- return result + val
- return wrapped # returns the decorated function "add_together"
- return decorator # returns the definition of the decorator "addint"
- # specifically built to return an extra 5 to the sum
- @addint(5)
- def add_together(a, b):
- return a + b
- print add_together(1, 2)
- # prints 8, not 3
Add Comment
Please, Sign In to add comment