RolifyCommunity / rolify

Role management library with resource scoping
https://rolifycommunity.github.io/rolify/
MIT License
3.17k stars 405 forks source link

How can I cache the result of with_role method? #248

Open kikikiblue opened 10 years ago

kikikiblue commented 10 years ago

Hi, I want to cache the result of with_role method, but it is not cached. (do always query to database) I guess it is because the result of with_role method is not the ActiveRecord::Relation, but I could not know how can I cache this. I do like this.

Rails.cache.fetch('admin'){User.with_role(:admin)}

Thanks.

tmaier commented 1 month ago

I think this shows nicely how this can be done: https://github.com/RolifyCommunity/rolify/issues/538#issuecomment-1034857085