Use mem_cache_store instead of dalli_store

`dalli_store` is deprecated since dalli 2.7.11.

We can now enable cache_versioning. We didn't enable it when upgrading
to Rails 5.2 because of possible incompatibility with `dalli_store` [1],
even though apparently some the issues were fixed in dalli 2.7.9 and
dalli 2.7.10 [2].

Since using cache versioning makes cache expiration more efficient, and
I'm not sure whether the options we were passing to the dalli store are
valid with memcache store (documentation here is a bit lacking), I'm
just removing the option we used to double the default cache size on
production.

[1] https://www.schneems.com/2018/10/17/cache-invalidation-complexity-rails-52-and-dalli-cache-store
[2] https://github.com/petergoldstein/dalli/blob/master/History.md
This commit is contained in:
Javi Martín
2021-08-15 15:17:10 +02:00
parent 1d594d1622
commit e01a94d7bd
10 changed files with 32 additions and 36 deletions

View File

@@ -28,10 +28,6 @@ module Consul
# Use local forms with `form_with`, so it works like `form_for` # Use local forms with `form_with`, so it works like `form_for`
config.action_view.form_with_generates_remote_forms = false config.action_view.form_with_generates_remote_forms = false
# Keep disabling cache versioning until we verify it's compatible
# with `:dalli_store` and with the way we cache stats
config.active_record.cache_versioning = false
# Keep using AES-256-CBC for message encryption in case it's used # Keep using AES-256-CBC for message encryption in case it's used
# in any CONSUL installations # in any CONSUL installations
config.active_support.use_authenticated_message_encryption = false config.active_support.use_authenticated_message_encryption = false

View File

@@ -57,7 +57,7 @@ Rails.application.configure do
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production. # Use a different cache store in production.
config.cache_store = :dalli_store, { value_max_bytes: 2000000 } config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server. # Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = "http://assets.example.com" # config.action_controller.asset_host = "http://assets.example.com"

View File

@@ -56,7 +56,7 @@ Rails.application.configure do
config.log_tags = [:request_id] config.log_tags = [:request_id]
# Use a different cache store in production. # Use a different cache store in production.
config.cache_store = :dalli_store, { value_max_bytes: 2000000 } config.cache_store = :mem_cache_store
# Use a real queuing backend for Active Job (and separate queues per environment) # Use a real queuing backend for Active Job (and separate queues per environment)
# config.active_job.queue_adapter = :resque # config.active_job.queue_adapter = :resque

View File

@@ -57,7 +57,7 @@ Rails.application.configure do
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production. # Use a different cache store in production.
config.cache_store = :dalli_store config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server. # Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = "http://assets.example.com" # config.action_controller.asset_host = "http://assets.example.com"

View File

@@ -6,7 +6,7 @@ describe "Cache flow" do
debate = create(:debate, tag_list: "Good, Bad") debate = create(:debate, tag_list: "Good, Bad")
tag = Tag.find_by(name: "Bad") tag = Tag.find_by(name: "Bad")
expect { tag.destroy }.to change { debate.reload.cache_key } expect { tag.destroy }.to change { debate.reload.cache_version }
end end
end end
end end

View File

@@ -86,33 +86,33 @@ describe Comment do
it "expires cache when it has a new vote" do it "expires cache when it has a new vote" do
expect { create(:vote, votable: comment) } expect { create(:vote, votable: comment) }
.to change { comment.updated_at } .to change { comment.cache_version }
end end
it "expires cache when hidden" do it "expires cache when hidden" do
expect { comment.hide } expect { comment.hide }
.to change { comment.updated_at } .to change { comment.cache_version }
end end
it "expires cache when the author is hidden" do it "expires cache when the author is hidden" do
expect { comment.user.hide } expect { comment.user.hide }
.to change { [comment.reload.updated_at, comment.author.updated_at] } .to change { [comment.reload.cache_version, comment.author.cache_version] }
end end
it "expires cache when the author is erased" do it "expires cache when the author is erased" do
expect { comment.user.erase } expect { comment.user.erase }
.to change { [comment.reload.updated_at, comment.author.updated_at] } .to change { [comment.reload.cache_version, comment.author.cache_version] }
end end
it "expires cache when the author changes" do it "expires cache when the author changes" do
expect { comment.user.update(username: "Isabel") } expect { comment.user.update(username: "Isabel") }
.to change { [comment.reload.updated_at, comment.author.updated_at] } .to change { [comment.reload.cache_version, comment.author.cache_version] }
end end
it "expires cache when the author's organization get verified" do it "expires cache when the author's organization get verified" do
create(:organization, user: comment.user) create(:organization, user: comment.user)
expect { comment.user.organization.verify } expect { comment.user.organization.verify }
.to change { [comment.reload.updated_at, comment.author.updated_at] } .to change { [comment.reload.cache_version, comment.author.cache_version] }
end end
end end

View File

@@ -351,48 +351,48 @@ describe Debate do
it "expires cache when it has a new comment" do it "expires cache when it has a new comment" do
expect { create(:comment, commentable: debate) } expect { create(:comment, commentable: debate) }
.to change { debate.updated_at } .to change { debate.cache_version }
end end
it "expires cache when it has a new vote" do it "expires cache when it has a new vote" do
expect { create(:vote, votable: debate) } expect { create(:vote, votable: debate) }
.to change { debate.updated_at } .to change { debate.cache_version }
end end
it "expires cache when it has a new flag" do it "expires cache when it has a new flag" do
expect { create(:flag, flaggable: debate) } expect { create(:flag, flaggable: debate) }
.to change { debate.reload.updated_at } .to change { debate.reload.cache_version }
end end
it "expires cache when it has a new tag" do it "expires cache when it has a new tag" do
expect { debate.update(tag_list: "new tag") } expect { debate.update(tag_list: "new tag") }
.to change { debate.updated_at } .to change { debate.cache_version }
end end
it "expires cache when hidden" do it "expires cache when hidden" do
expect { debate.hide } expect { debate.hide }
.to change { debate.updated_at } .to change { debate.cache_version }
end end
it "expires cache when the author is hidden" do it "expires cache when the author is hidden" do
expect { debate.author.hide } expect { debate.author.hide }
.to change { [debate.reload.updated_at, debate.author.updated_at] } .to change { [debate.reload.cache_version, debate.author.cache_version] }
end end
it "expires cache when the author is erased" do it "expires cache when the author is erased" do
expect { debate.author.erase } expect { debate.author.erase }
.to change { [debate.reload.updated_at, debate.author.updated_at] } .to change { [debate.reload.cache_version, debate.author.cache_version] }
end end
it "expires cache when its author changes" do it "expires cache when its author changes" do
expect { debate.author.update(username: "Eva") } expect { debate.author.update(username: "Eva") }
.to change { [debate.reload.updated_at, debate.author.updated_at] } .to change { [debate.reload.cache_version, debate.author.cache_version] }
end end
it "expires cache when the author's organization get verified" do it "expires cache when the author's organization get verified" do
create(:organization, user: debate.author) create(:organization, user: debate.author)
expect { debate.author.organization.verify } expect { debate.author.organization.verify }
.to change { [debate.reload.updated_at, debate.author.updated_at] } .to change { [debate.reload.cache_version, debate.author.cache_version] }
end end
end end

View File

@@ -386,48 +386,48 @@ describe Proposal do
it "expires cache when it has a new comment" do it "expires cache when it has a new comment" do
expect { create(:comment, commentable: proposal) } expect { create(:comment, commentable: proposal) }
.to change { proposal.updated_at } .to change { proposal.cache_version }
end end
it "expires cache when it has a new vote" do it "expires cache when it has a new vote" do
expect { create(:vote, votable: proposal) } expect { create(:vote, votable: proposal) }
.to change { proposal.updated_at } .to change { proposal.cache_version }
end end
it "expires cache when it has a new flag" do it "expires cache when it has a new flag" do
expect { create(:flag, flaggable: proposal) } expect { create(:flag, flaggable: proposal) }
.to change { proposal.reload.updated_at } .to change { proposal.reload.cache_version }
end end
it "expires cache when it has a new tag" do it "expires cache when it has a new tag" do
expect { proposal.update(tag_list: "new tag") } expect { proposal.update(tag_list: "new tag") }
.to change { proposal.updated_at } .to change { proposal.cache_version }
end end
it "expires cache when hidden" do it "expires cache when hidden" do
expect { proposal.hide } expect { proposal.hide }
.to change { proposal.updated_at } .to change { proposal.cache_version }
end end
it "expires cache when the author is hidden" do it "expires cache when the author is hidden" do
expect { proposal.author.hide } expect { proposal.author.hide }
.to change { [proposal.reload.updated_at, proposal.author.updated_at] } .to change { [proposal.reload.cache_version, proposal.author.cache_version] }
end end
it "expires cache when the author is erased" do it "expires cache when the author is erased" do
expect { proposal.author.erase } expect { proposal.author.erase }
.to change { [proposal.reload.updated_at, proposal.author.updated_at] } .to change { [proposal.reload.cache_version, proposal.author.cache_version] }
end end
it "expires cache when its author changes" do it "expires cache when its author changes" do
expect { proposal.author.update(username: "Eva") } expect { proposal.author.update(username: "Eva") }
.to change { [proposal.reload.updated_at, proposal.author.updated_at] } .to change { [proposal.reload.cache_version, proposal.author.cache_version] }
end end
it "expires cache when the author's organization get verified" do it "expires cache when the author's organization get verified" do
create(:organization, user: proposal.author) create(:organization, user: proposal.author)
expect { proposal.author.organization.verify } expect { proposal.author.organization.verify }
.to change { [proposal.reload.updated_at, proposal.author.updated_at] } .to change { [proposal.reload.cache_version, proposal.author.cache_version] }
end end
end end

View File

@@ -484,18 +484,18 @@ describe User do
it "expires cache with becoming a moderator" do it "expires cache with becoming a moderator" do
expect { create(:moderator, user: user) } expect { create(:moderator, user: user) }
.to change { user.updated_at } .to change { user.cache_version }
end end
it "expires cache with becoming an admin" do it "expires cache with becoming an admin" do
expect { create(:administrator, user: user) } expect { create(:administrator, user: user) }
.to change { user.updated_at } .to change { user.cache_version }
end end
it "expires cache with becoming a veridied organization" do it "expires cache with becoming a veridied organization" do
create(:organization, user: user) create(:organization, user: user)
expect { user.organization.verify } expect { user.organization.verify }
.to change { user.reload.updated_at } .to change { user.reload.cache_version }
end end
end end

View File

@@ -34,7 +34,7 @@ shared_examples "map validations" do
mappable.save! mappable.save!
expect { map_location.update(latitude: 12.34) } expect { map_location.update(latitude: 12.34) }
.to change { mappable.reload.updated_at } .to change { mappable.reload.cache_version }
end end
end end
end end