Skip to content
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 doesn't seem to work correctly #15

Open
ekampp opened this issue May 7, 2023 · 1 comment
Open

Caching doesn't seem to work correctly #15

ekampp opened this issue May 7, 2023 · 1 comment

Comments

@ekampp
Copy link

ekampp commented May 7, 2023

Hey 👋🏼

First off, this is a great gem! I have enjoyed working with it.

I started caching my serializer using the cached macro. As I understand from the documentation, that would use the cache_key on the resource.

It does cache the first time I serialize the resource. Then I updated the resource and serialized it again. The second serialization uses the cached JSON, even though the resource has been updated.

Thanks,
Emil

@hboisgibault
Copy link

hboisgibault commented May 22, 2024

Caching uses "cache_key" by default and not "cache_key_with_version" that includes the updated_at hash. That is why it behaves like this.
Example to solve this :

class VoteSerializer < Oj::Serializer
  cached_with_key ->(object) { object.cache_key_with_version }
  attributes :id, :voteable_id, :voteable_type, :user_id
  belongs_to :author
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants