Skip to content

Commit

Permalink
Add solid cache to dev and prod
Browse files Browse the repository at this point in the history
  • Loading branch information
fiveNinePlusR committed Nov 12, 2024
1 parent c2526b2 commit 32996fd
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 3 deletions.
2 changes: 2 additions & 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 Expand Up @@ -74,3 +75,4 @@ group :development, :test do
gem 'pry'
gem 'rails_real_favicon'
end

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

0 comments on commit 32996fd

Please sign in to comment.