-
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
Change the fetch method to deal with recyclable key cache strategy #2288
Conversation
#cache_key_with_key
when available#cache_key_with_key
when available
#cache_key_with_key
when available#cache_key_with_key
when available
Would you mind rebasing off of 0-10-stable? |
@bf4 Hi there :) this is already rebased against 0-10-stable |
#cache_key_with_key
when available
Looking at AppVeyor failures on Ruby 2.3
|
hey, it passed! |
@@ -229,6 +229,7 @@ def fetch_attributes(fields, cached_attributes, adapter_instance) | |||
def fetch(adapter_instance, cache_options = serializer_class._cache_options, key = nil) | |||
if serializer_class.cache_store | |||
key ||= cache_key(adapter_instance) | |||
cache_options = (cache_options || {}).merge(version: object_cache_version) if object_cache_version |
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.
so this will always be merged in, hmm
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.
Do you think it is likely to create issues in other parts of the code?
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.
I'm not familiar enough with the Rails code changes to be really sure.
I'd look at https://blog.heroku.com/cache-invalidation-rails-5-2-dalli-store to get any ideas.
How does it fail without this PR?
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.
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.
@bf4 I have added a test that you can see failing without the rest of the fixes in this pr: https://github.com/rails-api/active_model_serializers/pull/2288/files#diff-337d3920ba1fab97fd9fdd688d7664f3R152 :)
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.
fwiw, this could be
cache_options = (cache_options || {}).merge!(version: object_cache_version).tap(&:compact!)
Hash#compact removes members with nil keys
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.
Hello @cintamani . As per the objective of this PR, do we really need to send the version
option here to fix the issue of AMS introduced since rails-5.2.0 recyclable cache key when ActiveRecord::Base.cache_versioning = true
.
If AMS is supposed to keep working with cache keys of the form model/id-timestamp
as usual, we can just follow the steps inside #object_cache_key
method as much like https://github.com/rails/rails/blob/master/activesupport/lib/active_support/cache.rb#L94 that you already did in the first commit of this PR: 7d498d2
If AMS ever decides to support recyclable cache keys like Rails in future, this PR rails/rails#29092 might help to implement the case.
Thanks.
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.
do we really need to send the version option here ?
@wasifhossain are you saying you think this PR takes the wrong approach?
It's unclear to me if your review is based on usage of recyclable cache keys or not. I believe @cintamani is using this in production
Ok, I'm happy to merge this when you're happy with it |
@bf4 thanks 🙇♀️ ASAP I have some time to test it one last time I'll merge it :) |
@cintamani would you like this merged now? (I'm not confident I understand your last comment as intended) |
@bf4 sorry I'm not very active here 🙇♀️I have tested it again in my local environment and it still looks good and working as intended. But consider we are not currently using this in production yet due to issues with the Dalli gem. If you are still up for it, I will merge this one in tomorrow. |
@cintamani Since the pace of development here is pretty slow, I'd prefer waiting for you to confirm it works for you in production before I merging this PR. That ok? |
@bf4 totally :) I'll keep you posted |
Can we get this merged please? None of my cached objects ever update, even with |
@maxrosecollins have you confirmed it works for you in prod? Obviously we can merge it. But I would like confirmation not only that tests pass, but that it solves the problem it's intended to. I'm not currently using AMS. |
I tried to
I got this error
Which is strange because I can use the other branches :/ |
@maxrosecollins This isn't really the place to debug bundling a Gem from GitHub... I see https://github.com/cintamani/active_model_serializers/tree/patch-1 is at 7427d89 so I'm not really sure what oddities in your Gemfile are causing the problem. Try specified the absolute git url, and it that doesn't work, probably try a forum or slack. |
Sure...
Well I have tried all of these different methods. Have you tried installing
it?
…On Tue, 22 Jan 2019 at 20:04, Benjamin Fleischer ***@***.***> wrote:
@maxrosecollins <https://github.com/maxrosecollins> This isn't really the
place to debug bundling a Gem from GitHub...
I see https://github.com/cintamani/active_model_serializers/tree/patch-1
is at 7427d89
<7427d89>
so I'm not really sure what oddities in your Gemfile are causing the
problem. Try specified the absolute git url, and it that doesn't work,
probably try a forum or slack. git: "
https://github.com/cintamani/active_model_serializers.git"
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2288 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAv3PR4ju2nUbwI3eI7ILufhWZC7HFvLks5vF27NgaJpZM4XB80X>
.
|
@maxrosecollins like I said, this isn't the place to debug installing a gem from github. It makes the conversation on the topic of the PR hard to follow. Also, though I'm not using AMS, I just added the prescribed line to my Gemfile and successfully installed it. So, whatever is happening on your computer is 99.99999% certain to be unrelated to AMS. I wish I had the bandwidth to help you further and a place for that, but I don't right now. I am sorry. I'm just one person taking time away from his work to try and help make sure changes like this PR help people (and not cause harm) here my line in my Gemfile. I'm using Ruby 2.4.4, bundler 1.16.1, Rails 5.0.7 gem "active_model_serializers", git: "https://github.com/cintamani/active_model_serializers.git", branch: "patch-1" If you found a bug in bundler, they'll ask you to make a test repo to demonstrate and you can post an issue there. |
No worries. I'll take a look and see if I can get it working. |
@maxrosecollins this version works for sure 7d498d2 let me know if you get the time to make this PR's code work. I am very full those days and last time I have checked I found the error you are mentioning too. Still didn't have time to look at it properly. |
I can confirm the fact that this commit 7d498d2 (1st commit of this PR) should work 🎉 . Working excellent 👌 on our production app with this cherry-pick gomalindo@823b558, i.e. cache key expires properly in both cases when Unfortunately, unlike that single commit, this PR does not work as expected :( TL;DR collection_serializer cache keys don't expire at all using this PR, resulting in stale cache valuesFor those who are not concerned yet what this PR is trying to solve, I would humbly request to have a quick visit to these links
In short, when But when To read/write the latest cache value, we need to provide the Here are some examples to highlight the behavior of a recyclable cache key
This is what the PR tried to do exactly: https://github.com/rails-api/active_model_serializers/pull/2288/files#diff-b762caa6dd51036307106006dd81600f. So the version info is passed while fetching the cache value. Now we can discuss the actual issue. For collection serializer, the serialization happens in this sequence:
Here the thing to note is: once the cache is written for some key, it will be read using Summary (assuming a model has been updated multiple times):
So my humble opinion is that we stick with the form of cache key that would embed the version info itself as before i.e |
Yes. The idea behind is that we start sending the key and versions as 2 separate value to the cache gem. But since not even |
If Trevis is happy, I'm happy for you to merge this. And yes I would like to be added as a collaborator if you are happy with it :) |
@bf4 looks like we have lost support to 4.2 (also is Appveyor suppose to run Rails 4.2 only 🤔?) |
@cintamani at the end of the day, appveyor runs whatever maintainers consider a valuable burden to maintain. I'm ok with adding more complexity to the appveyor config, but that should be balanced in consideration of what it might be testing that travis isn't. Having >0 Rails version on appveyor is valuable. Having >1 is up for grabs :) |
@bf4 i would also be very happy to be a collaborator. Would appreciate some directions from you to be effective enough with the role. Thanks |
I've sent you both invites |
@bf4 Rails 4.2 versions are in the list of "Allowed Failures" for travis so I suggest we update the rails version on AppVeyor too. Also the 4.2 rails version failures doesn't look related to the code in this PR, can you confirm it? Also, can you confirm that we are happy for the next released version of AMS to not support Rails 4.2? |
? active_model_serializers/.travis.yml Lines 47 to 62 in 209834d
|
@bf4 sorry my mistake. The way Travis show the |
Co-Authored-By: cintamani <cintamani.puddu@gmail.com>
wtf failures
|
Yep saw it on Appveyor first but I ignored it. I see Travis is having the same issue 😩investigating |
@cintamani the good news it, you now have the power to create a PR to fix it and merge when green :) |
Run tests again
…ek is not compatible with the adapters currently in use
We are very unlucky! Looks like the issue is the newly released version of sqlite3 we are using in our test. It was released on the 4th of February, just in time to mess up with this PR 😆 |
@bf4 will you deal with creating a new release? Otherwise I'll give it a go myself |
@cintamani you can't release until you get rubygems permissions. I'm going to wait a little bit before adding you as a gem owner. I juste released 0.10.9 https://twitter.com/rubygems/status/1093924332659789827 |
Thank you, @bf4! I have never dealt with maintaining a public gem before, so forgive my ignorance about the RubyGems permissions 🙂 |
@cintamani it's a pretty common thing to forget or just not consider. The gems we install are from rubygems.org. Only gem owners can 'push' a gem |
I have one question, if you already get product, why use cache? @wasifhossain |
@shaojunda the example was intended to demonstrate the behavior of a recyclable cache key. |
I have always wanted to try the recyclable cache key, but I have never figured out how to use it. Do you have an example for use in a production environment? @wasifhossain |
In order to keep compatibility between the AMS cache feature and with Rails > 5.1 cache versioning which introduces Recyclable Keys, we have to account for the version of the cache separately from the cache key.
This PR address the issue for application with Rails version > 5.1 where the
cache_versioning
setting istrue
More info: #2287