mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 17:21:38 -05:00
Introduce SolidCache
This commit is contained in:
parent
a95d362b63
commit
3a955b8e51
8 changed files with 71 additions and 6 deletions
1
Gemfile
1
Gemfile
|
|
@ -44,6 +44,7 @@ gem 'sprockets-rails'
|
||||||
gem 'stimulus-rails'
|
gem 'stimulus-rails'
|
||||||
gem 'strong_migrations'
|
gem 'strong_migrations'
|
||||||
gem 'solid_cable', '~> 3.0'
|
gem 'solid_cable', '~> 3.0'
|
||||||
|
gem 'solid_cache', '1.0.7'
|
||||||
gem 'solid_queue', '~> 1.1'
|
gem 'solid_queue', '~> 1.1'
|
||||||
gem 'tailwindcss-rails'
|
gem 'tailwindcss-rails'
|
||||||
gem 'turbo-rails'
|
gem 'turbo-rails'
|
||||||
|
|
|
||||||
|
|
@ -457,6 +457,10 @@ GEM
|
||||||
activejob (>= 7.2)
|
activejob (>= 7.2)
|
||||||
activerecord (>= 7.2)
|
activerecord (>= 7.2)
|
||||||
railties (>= 7.2)
|
railties (>= 7.2)
|
||||||
|
solid_cache (1.0.7)
|
||||||
|
activejob (>= 7.2)
|
||||||
|
activerecord (>= 7.2)
|
||||||
|
railties (>= 7.2)
|
||||||
solid_queue (1.1.5)
|
solid_queue (1.1.5)
|
||||||
activejob (>= 7.1)
|
activejob (>= 7.1)
|
||||||
activerecord (>= 7.1)
|
activerecord (>= 7.1)
|
||||||
|
|
@ -582,6 +586,7 @@ DEPENDENCIES
|
||||||
sidekiq-limit_fetch
|
sidekiq-limit_fetch
|
||||||
simplecov
|
simplecov
|
||||||
solid_cable (~> 3.0)
|
solid_cable (~> 3.0)
|
||||||
|
solid_cache (= 1.0.7)
|
||||||
solid_queue (~> 1.1)
|
solid_queue (~> 1.1)
|
||||||
sprockets-rails
|
sprockets-rails
|
||||||
stackprof
|
stackprof
|
||||||
|
|
|
||||||
15
config/cache.yml
Normal file
15
config/cache.yml
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
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
|
||||||
|
|
||||||
|
test:
|
||||||
|
<<: *default
|
||||||
|
|
||||||
|
production:
|
||||||
|
<<: *default
|
||||||
|
|
@ -26,18 +26,18 @@ Rails.application.configure do
|
||||||
|
|
||||||
# Enable/disable caching. By default caching is disabled.
|
# Enable/disable caching. By default caching is disabled.
|
||||||
# Run rails dev:cache to toggle caching.
|
# Run rails dev:cache to toggle caching.
|
||||||
|
config.cache_store = :solid_cache_store
|
||||||
|
config.solid_cache.connects_to = { database: { writing: :cache } }
|
||||||
|
|
||||||
if Rails.root.join('tmp/caching-dev.txt').exist?
|
if Rails.root.join('tmp/caching-dev.txt').exist?
|
||||||
config.action_controller.perform_caching = true
|
config.action_controller.perform_caching = true
|
||||||
config.action_controller.enable_fragment_cache_logging = true
|
config.action_controller.enable_fragment_cache_logging = true
|
||||||
|
|
||||||
config.cache_store = :redis_cache_store, { url: ENV['REDIS_URL'] }
|
|
||||||
config.public_file_server.headers = {
|
config.public_file_server.headers = {
|
||||||
'Cache-Control' => "public, max-age=#{2.days.to_i}"
|
'Cache-Control' => "public, max-age=#{2.days.to_i}"
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
config.action_controller.perform_caching = false
|
config.action_controller.perform_caching = false
|
||||||
|
|
||||||
config.cache_store = :redis_cache_store, { url: ENV['REDIS_URL'] }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
config.public_file_server.enabled = true
|
config.public_file_server.enabled = true
|
||||||
|
|
|
||||||
|
|
@ -73,8 +73,8 @@ 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
|
||||||
config.cache_store = :redis_cache_store, { url: ENV['REDIS_URL'] }
|
config.solid_cache.connects_to = { database: { writing: :cache } }
|
||||||
|
|
||||||
# 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
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,9 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
Rails.cache.delete('dawarich/app-version-check')
|
# Defer cache operations until after initialization to avoid SolidCache loading issues
|
||||||
|
Rails.application.config.after_initialize do
|
||||||
|
# Skip cache clearing when running the Rails console
|
||||||
|
unless defined?(Rails::Console) || File.basename($PROGRAM_NAME) == 'rails' && ARGV.include?('console')
|
||||||
|
Rails.cache.delete('dawarich/app-version-check') if Rails.cache.respond_to?(:delete)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
||||||
11
config/initializers/solid_cache.rb
Normal file
11
config/initializers/solid_cache.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
# Configure SolidCache
|
||||||
|
Rails.application.config.to_prepare do
|
||||||
|
# Only require the entries file as it seems the Entry class is defined there
|
||||||
|
begin
|
||||||
|
require 'solid_cache/store/entries'
|
||||||
|
rescue LoadError => e
|
||||||
|
Rails.logger.warn "Could not load SolidCache: #{e.message}"
|
||||||
|
end
|
||||||
|
end
|
||||||
27
db/cache_schema.rb
Normal file
27
db/cache_schema.rb
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
# 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.0].define(version: 1) do
|
||||||
|
# These are extensions that must be enabled in order to support this database
|
||||||
|
enable_extension "pg_catalog.plpgsql"
|
||||||
|
|
||||||
|
create_table "solid_cache_entries", force: :cascade do |t|
|
||||||
|
t.binary "key", null: false
|
||||||
|
t.binary "value", null: false
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.bigint "key_hash", null: false
|
||||||
|
t.integer "byte_size", 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
|
||||||
Loading…
Reference in a new issue