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

Add solid cache to dev and prod #1617

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ gem 'sassc-rails'
gem 'scout_apm'
gem 'simple_form'
gem 'simple_token_authentication'
gem 'solid_cache', '~> 1.0'
gem 'sprockets-rails'
gem 'strip_attributes'
gem 'tzinfo-data'
Expand Down
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,10 @@ GEM
simplecov (~> 0.19)
simplecov-html (0.13.1)
simplecov_json_formatter (0.1.4)
solid_cache (1.0.6)
activejob (>= 7.2)
activerecord (>= 7.2)
railties (>= 7.2)
spork (0.9.2)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
Expand Down Expand Up @@ -568,6 +572,7 @@ DEPENDENCIES
simple_token_authentication
simplecov
simplecov-cobertura
solid_cache (~> 1.0)
spork
sprockets-rails
strip_attributes
Expand Down
18 changes: 18 additions & 0 deletions config/cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
default: &default
store_options:
# Cap age of oldest cache entry to fulfill retention policies
# max_age: <%= 60.days.to_i %>
max_size: <%= 256.megabytes %>
namespace: <%= Rails.env %>

development:
<<: *default

staging:
<<: *default

test:
<<: *default

production:
<<: *default
2 changes: 1 addition & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
config.action_controller.perform_caching = true
config.action_controller.enable_fragment_cache_logging = false

config.cache_store = :memory_store
config.cache_store = :solid_cache_store
config.public_file_server.headers = { "Cache-Control" => "public, max-age=#{2.days.to_i}" }
else
config.action_controller.perform_caching = false
Expand Down
3 changes: 1 addition & 2 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@
# .then { |logger| ActiveSupport::TaggedLogging.new(logger) }

# Use a different cache store in production.
config.cache_store = :mem_cache_store
# config.cache_store = :memory_store, { size: 64.megabytes }
config.cache_store = :solid_cache_store

# Use a real queuing backend for Active Job (and separate queues per environment).
config.active_job.queue_adapter = :async
Expand Down
15 changes: 15 additions & 0 deletions db/migrate/20241112193702_create_cache.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true
class CreateCache < ActiveRecord::Migration[7.2]
def change
create_table "solid_cache_entries", force: :cascade do |t|
t.binary "key", limit: 1024, null: false
t.binary "value", limit: 536870912, null: false
t.datetime "created_at", null: false
t.integer "key_hash", limit: 8, null: false
t.integer "byte_size", limit: 4, null: false
t.index ["byte_size"], name: "index_solid_cache_entries_on_byte_size"
t.index ["key_hash", "byte_size"], name: "index_solid_cache_entries_on_key_hash_and_byte_size"
t.index ["key_hash"], name: "index_solid_cache_entries_on_key_hash", unique: true
end
end
end