-
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
Changing cache key not working #2031
Comments
I also met this problem, it cause me some problems,when i generate different format json data for the same model in method Index and Show, it will confuse the two formats, as the cache key set by me not working, the cache data of two json format was treated as one, store in redis. I can't get two json formats for one object. I checked the sourse code of gem, the key set in the model ***Serializer was not used first. This is the sourse code generating the key store in redis or other db. the key like this: "interviews/20-20170324091427000000/attributes"
It call the method cache_key(maybe this: http://apidock.com/rails/ActiveRecord/Base/cache_key) first. |
I thought I ran into this problem today too (hadn't seen the issue) but after a brief source dive it looks like this is just a bit of documentation confusion. class Koala
def cache_key
"#{super}/eucalyptus"
end
end
class KoalaController
def show
render Koala.find(params[:id])
end
end
class KoalaSerializer
attributes :id, :food, :claws
def object_cache_key
"#{object.cache_key}/from_serializer"
end
end |
I've just hit this too, but I think it's more than documentation confusion. If you pass a It's certainly not used in |
Expected behavior vs actual behavior
Changing a serializer-level cache key with the
key option
does not change the cache key.Steps to reproduce
With a basic controller
and basic serializer
I would expect the cache key to resemble something like:
When instead the key is:
I've verified that the expected key is not present in the cache (memcache in my case). The incorrect key that is being set instead is present in the cache and does contain the cached value, so the cache itself is working.
Environment
ActiveModelSerializers Version (commit ref if not on tag): 0.10.4
Output of
ruby -e "puts RUBY_DESCRIPTION"
:ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin16]
OS Type & Version: 10.12.2
Integrated application and version (e.g., Rails, Grape, etc): Rails 5.0.1, api mode
Backtrace
(e.g., provide any applicable backtraces from your application)
Additonal helpful information
Occurs with both
memcache/dalli
and Rail'smemory_store
.development.rb cache section:
The text was updated successfully, but these errors were encountered: