diff --git a/Gemfile b/Gemfile index 93e23cb15..2ec7d8309 100644 --- a/Gemfile +++ b/Gemfile @@ -15,6 +15,7 @@ gem "hotwire_combobox", github: "josefarias/hotwire_combobox", branch: :main gem "bootsnap", require: false gem "puma", ">= 5.0" gem "solid_cable", ">= 3.0" +gem "solid_cache", "~> 1.0" gem "sqlite3", ">= 2.0" gem "thruster", require: false diff --git a/Gemfile.lock b/Gemfile.lock index b38e63f5b..b153fc0cf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -318,6 +318,10 @@ GEM activejob (>= 7.2) activerecord (>= 7.2) railties (>= 7.2) + solid_cache (1.0.6) + activejob (>= 7.2) + activerecord (>= 7.2) + railties (>= 7.2) sqlite3 (2.5.0-aarch64-linux-gnu) sqlite3 (2.5.0-aarch64-linux-musl) sqlite3 (2.5.0-arm-linux-gnu) @@ -393,6 +397,7 @@ DEPENDENCIES sentry-rails sentry-ruby solid_cable (>= 3.0) + solid_cache (~> 1.0) sqlite3 (>= 2.0) stimulus-rails thruster diff --git a/config/cache.yml b/config/cache.yml new file mode 100644 index 000000000..253588727 --- /dev/null +++ b/config/cache.yml @@ -0,0 +1,17 @@ +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: + database: cache + <<: *default + +test: + <<: *default + +production: + database: cache + <<: *default diff --git a/config/database.yml b/config/database.yml index a4e0188c1..441886e48 100644 --- a/config/database.yml +++ b/config/database.yml @@ -17,6 +17,10 @@ development: <<: *default database: storage/development_cable.sqlite3 migrations_paths: db/cable_migrate + cache: + <<: *default + database: storage/development_cache.sqlite3 + migrations_paths: db/cache_migrate # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". @@ -33,3 +37,7 @@ production: <<: *default database: storage/production_cable.sqlite3 migrations_paths: db/cable_migrate + cache: + <<: *default + database: storage/production_cache.sqlite3 + migrations_paths: db/cache_migrate diff --git a/config/environments/development.rb b/config/environments/development.rb index c2c25942e..838b0f7e3 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -23,7 +23,7 @@ Rails.application.configure do config.action_controller.perform_caching = true config.action_controller.enable_fragment_cache_logging = true - 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}" } diff --git a/config/environments/production.rb b/config/environments/production.rb index 2b09c3501..705d6fcd7 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -59,7 +59,7 @@ Rails.application.configure do config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info") # Use a different cache store in production. - # config.cache_store = :mem_cache_store + config.cache_store = :solid_cache_store # Use a real queuing backend for Active Job (and separate queues per environment). # config.active_job.queue_adapter = :resque diff --git a/db/cache_schema.rb b/db/cache_schema.rb new file mode 100644 index 000000000..39bb04aae --- /dev/null +++ b/db/cache_schema.rb @@ -0,0 +1,24 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema[8.1].define(version: 1) do + 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