python-cache

Caching for humans
Download

python-cache Ranking & Summary

Advertisement

  • Rating:
  • License:
  • MIT/X Consortium Lic...
  • Price:
  • FREE
  • Publisher Name:
  • Jay Adkisson
  • Publisher web site:
  • https://github.com/jayferd/

python-cache Tags


python-cache Description

python-cache is a Python module that provides caching for humans.Usage:import pylibmcfrom cache import Cachebackend = pylibmc.Client()cache = Cache(backend)@cache("mykey")def some_expensive_method(): sleep(10) return 42# writes 42 to the cachesome_expensive_method()# reads 42 from the cachesome_expensive_method()# re-calculates and writes 42 to the cachesome_expensive_method.refresh()# get the cached value or throw an errorsome_expensive_method.cached()# get the cached value or return 3some_expensive_method.cached(default=3)OptionsOptions can be passed to either the Cache constructor or the decorator. Options passed to the decorator take precedence. Available options are:enabled If `False`, the backend cache will not be used at all, and your functions will be run as-is. This is useful for development, when the backend cache may not be present at all. Default: Truebust If `True`, the values in the backend cache will be ignored, and new data will be calculated and written over the old values. Default: FalseThe remaining options, if given, will be passed as keyword arguments to the backend's set method. This is useful for things like expiration times - for example, using pylibmc:@cache("some_key", time=1000)def expensive_method(): # ...P.S.If you're a Ruby user, check out the analogous Cacher library for RubyProduct's homepage


python-cache Related Software