-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ranges of keys #9
Comments
Seems like a nice functionality for selective cache invalidation. But instead of the name "range of keys", what do you think about "key namespace"? Also, how would the developer call the selective expiration? Perhaps a method attached to the decorator? Would require to convert the decorator to a class, I think. |
Key namespace sounds better than range, for sure. I honestly did not think through this, but perhaps adding a class method to the SimpleCache class is a good enough answer. |
The class method would be like this |
I'd be lying if I said that I am very familiar with decorator methods, but your idea does sound good. And, as for class method I think a descriptive and simple method is great. It should not require any arguments other than the namespace name. |
Sorry, I've edited my last comment because I misread your suggestion. Now, how to implement it? Maybe adding a namespace prefix and using KEYS command to get the keys with that prefix for deletion? |
Namespace prefix is one way. What I was thinking is having keys grouped by set, with each set effectively being the namespace name. Example: set_super_slow_funcs [keyblah, keyblah, etc.] Am I making sense? |
Makes sense. But what are the advantages of using a set of keys in this case? |
I think, to me a set is a more natural way of doing this, after all that is the point of a set, grouping of unique entries, no? In reality I am sure that it is not necessarily the most efficient way of doing things. Though, I think I would choose elegance over efficiency here. |
While I agree on theory that sets are a more elegant approach than a prefix, they would require a SADD and a SET operation at cache insert. On cache invalidation, a SMEMBERS, many DEL (for each member) and another DEL (for the set) would be required. I would like to hear @vivekn thoughts on this. |
I think your approach is more efficient, and mine is more elegant. Efficiency tends to win out. Your approach is I think elegant enough to be the best answer here. |
I was trying to implement the |
The least elegant answer is to pass all of this information to the classmethod. The better answer maybe to track all connections in some index and pass a connection to the classmethod? |
While this is a feature that would be great to have, the implementation might be tricky and I'm not sure if I follow the discussion completely. I have a few questions regarding this:
These are some issues that need to be worked out. As for the connection problem, implementing it as a normal method instead of classmethod might solve the problem for time being. The way things are now, the user would have to create a SimpleCache instance explicitly anyway, if he/she wants to change the connection settings. |
It is confusing, because we need a connection to flush, but it makes more If we store the created connections in a "static" (class level) variable, For the sake of simplicity and clean code, I think it is better to discard Also, we need to think about possible race conditions. Perhaps the use of Answering your questions: 2013/2/22 Vivek Narayanan notifications@github.com
|
Added a possible solution that worked for my needs in pull request #23 I had several groups of related cache items cached via the cache_it decorator, that would all need to be expired on certain conditions and I did not want to expire the whole set so I added a namespace argument to cache_it, and added a flush_namespace & expire_namespace |
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.
The text was updated successfully, but these errors were encountered: