-
Notifications
You must be signed in to change notification settings - Fork 19
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
caching? #13
Comments
I've actually been thinking about caching, but I haven't really planned to submit a PR to implement into the library. One of the things I like about virgen-acl is that it's dirt simple and can be conformed to almost any use case (that I have anyway). If virgen-acl implements caching then it will
If I write caching into virgen-acl for example I'm going to write a redis cache layer, which will probably suit most people, but it seems like A Bad Thing to turn away memcached die hards, you know? Or there are people who would be perfectly suited using an in-memory cache that I'm not particularly interested in writing because I wouldn't use it in my projects (I want TTL and I don't want to write TTL). My plan was to implement my own caching in my That being said, though, now that you've got me thinking about it I do like the idea of caching the permission lookup and not even executing the If you have suggestions, though, this is likely something I'm going to be exploring in the near future and if @djvirgen is on board it might be something worth implementing directly into the library. In the mean time the simplest way to implement caching would be something like
It's some extra boilerplate to your |
I like the idea of caching support, but I agree with @spruce-bruce that an opinionated solution might make this code less portable. One thing we can do to get around that is to provide a cache interface that you could use to wrap your own custom caching solution, for example (in pseudocode):
The idea being you could implement this interface and provide the instance to VirgenACL:
When a cache is provided, VirgenACL can automatically write to it after successfully determining access, and fetch from it prior to checking for access. If the We may need to think through this a bit more but overall what do you guys think of this approach? |
That suits me quite well. The other thing I hadn't thought about is the case where people are using this on the frontend and won't ever care about redis/db/whatever caching. The interface solution handles the frontend case perfectly in that you provide a different cache adapter for in your frontend acl instance than your backend. 👍 from me! I can probably volunteer some time to implement as well, though not likely in the near term (and if not me then I might make one of my coworkers do it). Either way I think this is a good idea. We would also end up writing a redis adapter that we could then publish for anybody to use |
Awesome! If I get some free time soon, I'll work on it and update you all here before I get started. Thanks for the feedback! |
Instead of calling from cache, and if cache doesn't exist, then call virgen, perhaps implement a layer on top that does the caching behind the scenes, so:
I personally don't think there's a need for TTL, what I would personally do is, whenever something is added/removed from a role or whatever, invalidate the relevant cache keys |
This is essentially what @djvirgen proposed, and will work really nicely. I was just giving an example of how to implement caching on top of virgen-acl until caching gets implemented into the library, since there's not really a good way to know when anybody will be able to free up time for this addition.
The use case for TTL (or some other manual invalidation) is for people (like myself) who are using callbacks in their I think TTL is important, but doesn't need to be implemented by virgen-acl, this could be left up to the individual cache adapters. |
Any plans for caching mechanisms?
The text was updated successfully, but these errors were encountered: