Play with solid_cache #34

Merged
atomaka merged 2 commits from solid-cache into main 2024-09-08 21:51:16 -04:00
7 changed files with 53 additions and 6 deletions

View file

@ -18,6 +18,7 @@ gem "jbuilder"
# Use Redis adapter to run Action Cable in production # Use Redis adapter to run Action Cable in production
# gem "redis", ">= 4.0.1" # gem "redis", ">= 4.0.1"
gem "solid_cache"
gem "solid_queue" gem "solid_queue"
# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis] # Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]

View file

@ -263,6 +263,10 @@ GEM
rexml (~> 3.2, >= 3.2.5) rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0) rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0) websocket (~> 1.0)
solid_cache (1.0.5)
activejob (>= 7.2)
activerecord (>= 7.2)
railties (>= 7.2)
solid_queue (0.8.2) solid_queue (0.8.2)
activejob (>= 7.1) activejob (>= 7.1)
activerecord (>= 7.1) activerecord (>= 7.1)
@ -325,6 +329,7 @@ DEPENDENCIES
rails! rails!
rubocop-rails-omakase rubocop-rails-omakase
selenium-webdriver selenium-webdriver
solid_cache
solid_queue solid_queue
sqlite3 (>= 1.4) sqlite3 (>= 1.4)
stimulus-rails stimulus-rails

View file

@ -10,8 +10,14 @@ default: &default
timeout: 5000 timeout: 5000
development: development:
<<: *default primary:
database: db/development.sqlite3 <<: *default
database: db/development.sqlite3
cache:
<<: *default
database: db/development_cache.sqlite3
migrations_paths: db/cache_migrate
# Warning: The database defined as "test" will be erased and # Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake". # re-generated from your development database when you run "rake".
@ -21,5 +27,10 @@ test:
database: db/test.sqlite3 database: db/test.sqlite3
production: production:
<<: *default primary:
database: db/production.sqlite3 <<: *default
database: storage/production.sqlite3
cache:
<<: *default
database: storage/production_cache.sqlite3
migrations_paths: db/cache_migrate

View file

@ -28,7 +28,7 @@ Rails.application.configure do
end end
# Change this to :null_store to avoid any caching # Change this to :null_store to avoid any caching
config.cache_store = :memory_store config.cache_store = :solid_cache_store
# Store uploaded files on the local file system (see config/storage.yml for options). # Store uploaded files on the local file system (see config/storage.yml for options).
config.active_storage.service = :local config.active_storage.service = :local

View file

@ -66,7 +66,7 @@ Rails.application.configure do
config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info") config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info")
# Use a different cache store in production. # 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). # Use a real queuing backend for Active Job (and separate queues per environment).
config.active_job.queue_adapter = :solid_queue config.active_job.queue_adapter = :solid_queue

16
config/solid_cache.yml Normal file
View file

@ -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

14
db/cache_schema.rb Normal file
View file

@ -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