diff --git a/personal/Gemfile b/personal/Gemfile index 135ee93..f27c081 100644 --- a/personal/Gemfile +++ b/personal/Gemfile @@ -122,3 +122,5 @@ gem 'marginalia' gem 'ox', require: false gem "solid_cache", "~> 1.0" + +gem "sqlite3", "~> 2.3" diff --git a/personal/Gemfile.lock b/personal/Gemfile.lock index 8d31f28..ab83a5d 100644 --- a/personal/Gemfile.lock +++ b/personal/Gemfile.lock @@ -449,6 +449,10 @@ GEM actionpack (>= 6.1) activesupport (>= 6.1) sprockets (>= 3.0.0) + sqlite3 (2.3.0) + mini_portile2 (~> 2.8.0) + sqlite3 (2.3.0-aarch64-linux-gnu) + sqlite3 (2.3.0-arm64-darwin) stimulus-rails (1.3.4) railties (>= 6.0.0) stringio (3.1.2) @@ -553,6 +557,7 @@ DEPENDENCIES sitemap_generator solid_cache (~> 1.0) sprockets-rails + sqlite3 (~> 2.3) stimulus-rails turbo-rails tzinfo-data diff --git a/personal/config/cache.yml b/personal/config/cache.yml new file mode 100644 index 0000000..2535887 --- /dev/null +++ b/personal/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/personal/config/database.yml b/personal/config/database.yml index d2d2d46..8c930d1 100644 --- a/personal/config/database.yml +++ b/personal/config/database.yml @@ -28,6 +28,10 @@ development: database: ro_development host: localhost migrations_paths: db/ro + cache: + adapter: sqlite3 + database: storage/development_cache.sqlite3 + migrations_paths: db/cache test: primary: @@ -84,3 +88,7 @@ production: password: <%= ENV["DATABASE_PASSWORD"] %> host: <%= ENV['DATABASE_HOST'] %> migrations_paths: db/ro + cache: + adapter: sqlite3 + database: storage/production_cache.sqlite3 + migrations_paths: db/cache diff --git a/personal/config/environments/development.rb b/personal/config/environments/development.rb index 1df6e16..1be57ad 100644 --- a/personal/config/environments/development.rb +++ b/personal/config/environments/development.rb @@ -42,20 +42,21 @@ if Rails.root.join('tmp/caching-dev.txt').exist? config.action_controller.perform_caching = true config.action_controller.enable_fragment_cache_logging = true + config.cache_store = :solid_cache_store - config.cache_store = :redis_cache_store, { url: "redis://localhost:6379/0", + # config.cache_store = :redis_cache_store, { url: "redis://localhost:6379/0", - connect_timeout: 30, # Defaults to 20 seconds - read_timeout: 0.2, # Defaults to 1 second - write_timeout: 0.2, # Defaults to 1 second - reconnect_attempts: 1, # Defaults to 0 - expires_in: 3.months, - error_handler: -> (method:, returning:, exception:) { + # connect_timeout: 30, # Defaults to 20 seconds + # read_timeout: 0.2, # Defaults to 1 second + # write_timeout: 0.2, # Defaults to 1 second + # reconnect_attempts: 1, # Defaults to 0 + # expires_in: 3.months, + # error_handler: -> (method:, returning:, exception:) { - Sentry.capture_exception exception, level: 'warning', - tags: { method: method, returning: returning } - } - } + # Sentry.capture_exception exception, level: 'warning', + # tags: { method: method, returning: returning } + # } + # } config.public_file_server.headers = { 'Cache-Control' => "public, max-age=#{2.days.to_i}" } diff --git a/personal/config/environments/production.rb b/personal/config/environments/production.rb index 66e470f..e718b20 100644 --- a/personal/config/environments/production.rb +++ b/personal/config/environments/production.rb @@ -65,8 +65,7 @@ config.log_tags = [:request_id] # Use a different cache store in production. - # config.cache_store = :mem_cache_store - config.cache_store = :redis_cache_store, { url: 'redis://localhost:6379/0', expires_in: 1.day } + config.cache_store = :solid_cache_store # Use a real queuing backend for Active Job (and separate queues per environment). diff --git a/personal/db/cache/20241124234620_solid_cache_init.rb b/personal/db/cache/20241124234620_solid_cache_init.rb new file mode 100644 index 0000000..732b7b3 --- /dev/null +++ b/personal/db/cache/20241124234620_solid_cache_init.rb @@ -0,0 +1,14 @@ +class SolidCacheInit < 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 diff --git a/personal/db/cache_schema.rb b/personal/db/cache_schema.rb new file mode 100644 index 0000000..7b5d919 --- /dev/null +++ b/personal/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[7.2].define(version: 2024_11_24_234620) 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