vivekn / redis-simple-cache Goto Github PK
View Code? Open in Web Editor NEWSimple redis based cache for storing results of python function calls, json encoded strings or html.
License: Other
Simple redis based cache for storing results of python function calls, json encoded strings or html.
License: Other
That'd be a good option to have cache_it() and cache_it_json() either auto-detecting instance methods or being marked of such a use case by, for example, strip_first_arg boolean parameter that'd perform something like
pickle.dumps(args[1:])
There's a side effect in such a use case, I know, but could be an option for those who know what they do.
In my case, using instance methods eliminates a need to call getLogger every time I need to log something and provides an option to use one, instance-wide, logger (which certainly cannot be pickled because of file descriptors inside any logger object).
I missed this earlier, but I found that the SimpleCache.make_key()
method uses the id of the instance in the key's prefix. The id is determined at runtime, so effectively a new cache is created every time the program is run. If the program is restarted the earlier cache is inaccessible. Is this really a good idea?
@fjsj I would like to hear your views on it.
So, in case I'm not understanding things correctly, is there a way to handle the following use case: I have a function which I need to cache most of the time, but in a few very specific cases I need it run its course. The function is grabbing things from a web api, most of these do not change but some do, and that fact only matters in one use case. Can I provide an additional keyword just for that specific use case?
e.g.
get_data(dont_cache=True)
I'm thinking the best place to implement this (in case this doesn't already exist) would be here. Thoughts?
This is because of direct version binding in requirements.txt:
redis==2.7.1
SETEX does not support this:
https://groups.google.com/d/msg/redis-db/DmtcGkZuD10/OZU16j4ZUpkJ
store() could probably include a check for expire=None and simply use SET for those requests.
Have I understood this issue properly? Would you like a patch for this?
It seems a simple fix bug that the cache_it_json
has the parameter namespace but it is passing always None to the inner function cache_it
This code currently doesn't work under Python 3. The to_unicode() function, and perhaps other things too.
If you wish to cache a method that uses keyword args you need to do it manually instead of using the decorator, which is annoying since it should be a simple fix to add a use_kwargs argument to cache_it that defaults to False, can be True for using all kwargs or can be a comma separated string of kwarg keys to use in the generation of the key
rediscache.py contains this code:
self.connection = RedisConnect(host=self.host,
port=self.port,
db=0,
password=password).connect()
so as you can see db is always 0
I am planning to implement initial conditions (seed values). Providing seed values can simplify the body of a recursive function significantly.
I image it looking something like this:
# Fibonacci
@cache_it(seed={0:0, 1:1})
def F(i): return F(i-1) + F(i-2)
Since the seed changes all the values of the function, the seed should be fed into the hash used for the function key.
Are there any other considerations I should take into account before implementation?
Does this sound like it falls within the scope of the goals of this repo?
It would be great to implement methods to expire not all keys in set but with specific args and specific functions.
It would be great to have infinite limit when 'limit' is set to, for example, 0
Hi,
Some ut cases failed, such as:
def test_decorator(self)
I think it would be nice to have ranges of keys, which are stored as members of a set. One should be able to define a range of any given name, and optionally add keys for any wrapped function to this set. Any number of sets should be possible. This would make it easier to selectively expire groups of keys prematurely, if necessary. I can see a use case for this being where a change made to some data elements will result in no-longer valid cached entries, but their expiration originally set on the wrapped function or functions has not yet been reached.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.