-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Use ActiveSupport::Cache.expand_cache_key for cache key expansions #1878
Conversation
@markiz, thanks for your PR! By analyzing the annotation information on this pull request, we identified @bf4, @kevintyll and @beauby to be potential reviewers |
2811e9e
to
04e08a0
Compare
what are the benefits of this? / what's the use case? |
We use non-primitive object as cache keys, another contrived example:
There wouldn't be any problem if AMS didn't try to |
@markiz lgtm,
|
@markiz thanks for that. I didn't know this was an old feature, and I had no idea people even did this. Certainly looks looks better than building your own cache key string. :-) |
@NullVoxPopuli yeah.. I'm not sure why it was removed. We use ActiveSupport::Cache which uses expand_cache_key but ¯_(ツ)_/¯ |
[ | ||
DerivedCacheKey.new(self, :name), | ||
DerivedCacheKey.new(self, :id) | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@markiz my only real concern is that these classes are really weird-looking. Would you mind adding some comments why you designed it this way? Be nice to future devs :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
7b6302a
to
d0e54da
Compare
Purpose
Allows using non-primitive objects as object cache key.
For example, we might want to return an array of objects that define
#cache_key
as our serialized object's#cache_key
Changes
join("/")
changed toActiveSupport::Cache.expand_cache_key
Caveats
Dependency on ActiveSupport (which we already have)
Additional helpful information
The test is a bit contrived, sorry about that.
#expand_cache_key
can be redefined to change the actual implementation.Previous version of AMS did use
ActiveSupport::Cache.expand_cache_key