-
Notifications
You must be signed in to change notification settings - Fork 16
Fix compatibility with Rails edge #64
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| source 'https://rubygems.org' | ||
|
|
||
| gemspec | ||
|
|
||
| gem "rails", github: "rails/rails", branch: "main" | ||
| gem "snappy" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,209 @@ | ||
|
|
||
| module LocalCacheBehavior | ||
| def test_local_writes_are_persistent_on_the_remote_cache | ||
| retval = @cache.with_local_cache do | ||
| @cache.write("foo", "bar") | ||
| end | ||
| assert retval | ||
| assert_equal "bar", @cache.read("foo") | ||
| end | ||
|
|
||
| def test_clear_also_clears_local_cache | ||
| @cache.with_local_cache do | ||
| @cache.write("foo", "bar") | ||
| @cache.clear | ||
| assert_nil @cache.read("foo") | ||
| end | ||
|
|
||
| assert_nil @cache.read("foo") | ||
| end | ||
|
|
||
| def test_cleanup_clears_local_cache_but_not_remote_cache | ||
| begin | ||
| @cache.cleanup | ||
| rescue NotImplementedError | ||
| skip | ||
| end | ||
|
|
||
| @cache.with_local_cache do | ||
| @cache.write("foo", "bar") | ||
| assert_equal "bar", @cache.read("foo") | ||
|
|
||
| @cache.send(:bypass_local_cache) { @cache.write("foo", "baz") } | ||
| assert_equal "bar", @cache.read("foo") | ||
|
|
||
| @cache.cleanup | ||
| assert_equal "baz", @cache.read("foo") | ||
| end | ||
| end | ||
|
|
||
| def test_local_cache_of_write | ||
| @cache.with_local_cache do | ||
| @cache.write("foo", "bar") | ||
| @peek.delete("foo") | ||
| assert_equal "bar", @cache.read("foo") | ||
| end | ||
| end | ||
|
|
||
| def test_local_cache_of_read_returns_a_copy_of_the_entry | ||
| skip if ActiveSupport.gem_version < Gem::Version.new('6.1') | ||
|
|
||
| @cache.with_local_cache do | ||
| @cache.write(:foo, type: "bar") | ||
| value = @cache.read(:foo) | ||
| assert_equal("bar", value.delete(:type)) | ||
| assert_equal({ type: "bar" }, @cache.read(:foo)) | ||
| end | ||
| end | ||
|
|
||
| def test_local_cache_of_read | ||
| @cache.write("foo", "bar") | ||
| @cache.with_local_cache do | ||
| assert_equal "bar", @cache.read("foo") | ||
| end | ||
| end | ||
|
|
||
| def test_local_cache_of_read_nil | ||
| @cache.with_local_cache do | ||
| assert_nil @cache.read("foo") | ||
| @cache.send(:bypass_local_cache) { @cache.write "foo", "bar" } | ||
| assert_nil @cache.read("foo") | ||
| end | ||
| end | ||
|
|
||
| def test_local_cache_of_write_nil | ||
| @cache.with_local_cache do | ||
| assert @cache.write("foo", nil) | ||
| assert_nil @cache.read("foo") | ||
| @peek.write("foo", "bar") | ||
| assert_nil @cache.read("foo") | ||
| end | ||
| end | ||
|
|
||
| def test_local_cache_of_write_with_unless_exist | ||
| @cache.with_local_cache do | ||
| @cache.write("foo", "bar") | ||
| @cache.write("foo", "baz", unless_exist: true) | ||
| assert_equal @peek.read("foo"), @cache.read("foo") | ||
| end | ||
| end | ||
|
|
||
| def test_local_cache_of_delete | ||
| @cache.with_local_cache do | ||
| @cache.write("foo", "bar") | ||
| @cache.delete("foo") | ||
| assert_nil @cache.read("foo") | ||
| end | ||
| end | ||
|
|
||
| def test_local_cache_of_delete_matched | ||
| begin | ||
| @cache.delete_matched("*") | ||
| rescue NotImplementedError | ||
| skip | ||
| end | ||
|
|
||
| @cache.with_local_cache do | ||
| @cache.write("foo", "bar") | ||
| @cache.write("fop", "bar") | ||
| @cache.write("bar", "foo") | ||
| @cache.delete_matched("fo*") | ||
| assert_not @cache.exist?("foo") | ||
| assert_not @cache.exist?("fop") | ||
| assert_equal "foo", @cache.read("bar") | ||
| end | ||
| end | ||
|
|
||
| def test_local_cache_of_exist | ||
| @cache.with_local_cache do | ||
| @cache.write("foo", "bar") | ||
| @peek.delete("foo") | ||
| assert @cache.exist?("foo") | ||
| end | ||
| end | ||
|
|
||
| def test_local_cache_of_increment | ||
| @cache.with_local_cache do | ||
| @cache.write("foo", 1, raw: true) | ||
| @peek.write("foo", 2, raw: true) | ||
| @cache.increment("foo") | ||
| assert_equal 3, Integer(@cache.read("foo", raw: true)) | ||
| end | ||
| end | ||
|
|
||
| def test_local_cache_of_decrement | ||
| @cache.with_local_cache do | ||
| @cache.write("foo", 1, raw: true) | ||
| @peek.write("foo", 3, raw: true) | ||
|
|
||
| @cache.decrement("foo") | ||
| assert_equal 2, Integer(@cache.read("foo", raw: true)) | ||
| end | ||
| end | ||
|
|
||
| def test_local_cache_of_fetch_multi | ||
| @cache.with_local_cache do | ||
| @cache.fetch_multi("foo", "bar") { |_key| true } | ||
| @peek.delete("foo") | ||
| @peek.delete("bar") | ||
| assert_equal true, @cache.read("foo") | ||
| assert_equal true, @cache.read("bar") | ||
| end | ||
| end | ||
|
|
||
| def test_local_cache_of_read_multi | ||
| @cache.with_local_cache do | ||
| @cache.write("foo", "foo", raw: true) | ||
| @cache.write("bar", "bar", raw: true) | ||
| values = @cache.read_multi("foo", "bar", raw: true) | ||
| assert_equal "foo", @cache.read("foo", raw: true) | ||
| assert_equal "bar", @cache.read("bar", raw: true) | ||
| assert_equal "foo", values["foo"] | ||
| assert_equal "bar", values["bar"] | ||
| end | ||
| end | ||
|
|
||
| def test_initial_object_mutation_after_write | ||
| skip if ActiveSupport.gem_version < Gem::Version.new('6.1') | ||
|
|
||
| @cache.with_local_cache do | ||
| initial = +"bar" | ||
| @cache.write("foo", initial) | ||
| initial << "baz" | ||
| assert_equal "bar", @cache.read("foo") | ||
| end | ||
| end | ||
|
|
||
| def test_initial_object_mutation_after_fetch | ||
| skip if ActiveSupport.gem_version < Gem::Version.new('6.1') | ||
|
|
||
| @cache.with_local_cache do | ||
| initial = +"bar" | ||
| @cache.fetch("foo") { initial } | ||
| initial << "baz" | ||
| assert_equal "bar", @cache.read("foo") | ||
| assert_equal "bar", @cache.fetch("foo") | ||
| end | ||
| end | ||
|
|
||
| def test_local_race_condition_protection | ||
| @cache.with_local_cache do | ||
| time = Time.now | ||
| @cache.write("foo", "bar", expires_in: 60) | ||
| Time.stub(:now, time + 61) do | ||
| result = @cache.fetch("foo", race_condition_ttl: 10) do | ||
| assert_equal "bar", @cache.read("foo") | ||
| "baz" | ||
| end | ||
| assert_equal "baz", result | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def test_local_cache_should_read_and_write_false | ||
| @cache.with_local_cache do | ||
| assert @cache.write("foo", false) | ||
| assert_equal false, @cache.read("foo") | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
These changes are not applied when Rails assigns
LocalStorein middleware here:https://github.com/rails/rails/blob/c903dfe618b8ed2b2c6d73b162a49fc4d478a855/activesupport/lib/active_support/cache/strategy/local_cache_middleware.rb#L28
This means that duping is broken for middleware-applied LocalCache when memcached_store is used, since the duping fixes above are not present in
ActiveSupport::Cache::Strategy::LocalCache::LocalStore.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.
Yup. I'll need to use a decorator or something like that instead.