From f8677f8a7825c0ae3270db6b3445f5b3d9abc2f3 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Sun, 8 Sep 2024 21:36:31 -0400 Subject: [PATCH] Check out solid_cache --- Gemfile | 1 + Gemfile.lock | 5 +++++ config/database.yml | 9 +++++++-- config/environments/production.rb | 2 +- config/solid_cache.yml | 16 ++++++++++++++++ db/cache_schema.rb | 14 ++++++++++++++ 6 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 config/solid_cache.yml create mode 100644 db/cache_schema.rb diff --git a/Gemfile b/Gemfile index 84f9cd1..4960cb9 100644 --- a/Gemfile +++ b/Gemfile @@ -18,6 +18,7 @@ gem "jbuilder" # Use Redis adapter to run Action Cable in production # gem "redis", ">= 4.0.1" +gem "solid_cache" gem "solid_queue" # Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis] diff --git a/Gemfile.lock b/Gemfile.lock index e02cc90..6dc1528 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -263,6 +263,10 @@ GEM rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2, < 3.0) websocket (~> 1.0) + solid_cache (1.0.5) + activejob (>= 7.2) + activerecord (>= 7.2) + railties (>= 7.2) solid_queue (0.8.2) activejob (>= 7.1) activerecord (>= 7.1) @@ -325,6 +329,7 @@ DEPENDENCIES rails! rubocop-rails-omakase selenium-webdriver + solid_cache solid_queue sqlite3 (>= 1.4) stimulus-rails diff --git a/config/database.yml b/config/database.yml index fcba57f..ee97168 100644 --- a/config/database.yml +++ b/config/database.yml @@ -21,5 +21,10 @@ test: database: db/test.sqlite3 production: - <<: *default - database: db/production.sqlite3 + primary: + <<: *default + database: storage/production.sqlite3 + cache: + <<: *default + database: storage/production_cache.sqlite3 + migrations_paths: db/cache_migrate diff --git a/config/environments/production.rb b/config/environments/production.rb index 08d3893..452d6b8 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -66,7 +66,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 = :solid_queue diff --git a/config/solid_cache.yml b/config/solid_cache.yml new file mode 100644 index 0000000..e20236f --- /dev/null +++ b/config/solid_cache.yml @@ -0,0 +1,16 @@ +default: &default + database: cache + 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 + +test: + <<: *default + +production: + <<: *default diff --git a/db/cache_schema.rb b/db/cache_schema.rb new file mode 100644 index 0000000..1646384 --- /dev/null +++ b/db/cache_schema.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +ActiveRecord::Schema[7.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