caching - How to cache value of a function in Python? -
i have function, given argument calculates corresponding value , returns it. returned value of function, depends on parameters, i'd cache (memoize) value somehow. furthermore, want able invalidate cached value.
it seems common need, trying avoid reinventing wheel.
what i'm looking advanced highly-configurable high-performance library (tool, framework, etc.) , changes lean possible. points are:
- efficiently handling concurrent requests
- being able use different cache backends (e.g. ram or db)
- retaining responsiveness on large scale data
what libraries use, , how compared?
this question doesn't make sense me. when start talking "high performance" , "concurrent requests" , you're not talking using python library within application -- sounds more using (or building) sort of dedicated, external specialized service or daemon.
personally, use mixture of memoization , 'lazy loaded' or 'deferred' properties define cache gets (and computes). 'lazy loaded', mean instead of pulling (or computing) cached data, create proxy object has information call get/create function cache on first access. when comes database backed material, i've found useful group cache misses , consolidate cache gets - allows me load in parallel when possible ( instead of multiple serial requests ).
dogpile.cache
takes care of cache administration (get, set, invalidate), configured store in memcached or dbm ( allows several backends ). use 2 lightweight objects (12lines?) handle deferred gets.
Comments
Post a Comment