Skip to content

Instantly share code, notes, and snippets.

@kgaughan
Created November 4, 2015 16:42
Show Gist options
  • Save kgaughan/67674968e62c0912d1da to your computer and use it in GitHub Desktop.
Save kgaughan/67674968e62c0912d1da to your computer and use it in GitHub Desktop.
retools caching example
import time
from retools.cache import cache_region, CacheRegion
@cache_region('short_term')
def myfunc(arg1):
print "In myfunc"
return 2 * arg1
def main():
CacheRegion.add_region('short_term', expires=2)
print "Answer is:", myfunc(5)
print "Answer is:", myfunc(10)
time.sleep(1)
print "Answer is:", myfunc(5)
time.sleep(1)
print "Answer is:", myfunc(5)
time.sleep(1)
print "Answer is:", myfunc(5)
print "Answer is:", myfunc(10)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment