Skip to content

Commit

Permalink
Replace Redis with Solid Cache
Browse files Browse the repository at this point in the history
  • Loading branch information
euxx committed Nov 13, 2024
1 parent 57d5aa8 commit 5737355
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ gem 'jsbundling-rails'
gem 'cssbundling-rails'
gem 'turbo-rails'
gem 'stimulus-rails'
gem 'redis', '~> 5'
gem 'solid_cache', '~> 1'
gem 'solid_queue', '~> 1'
gem 'mission_control-jobs'
# gem 'image_processing', '~> 1'
Expand Down
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,6 @@ GEM
ffi (~> 1.0)
rdoc (6.7.0)
psych (>= 4.0.0)
redis (5.3.0)
redis-client (>= 0.22.0)
redis-client (0.22.2)
connection_pool
regexp_parser (2.9.2)
reline (0.5.11)
io-console (~> 0.5)
Expand Down Expand Up @@ -337,6 +333,10 @@ GEM
concurrent-ruby (~> 1.0, >= 1.0.2)
skylight (6.0.4)
activesupport (>= 5.2.0)
solid_cache (1.0.6)
activejob (>= 7.2)
activerecord (>= 7.2)
railties (>= 7.2)
solid_queue (1.0.1)
activejob (>= 7.1)
activerecord (>= 7.1)
Expand Down Expand Up @@ -400,12 +400,12 @@ DEPENDENCIES
pry-rails
puma (~> 6)
rails (~> 8)
redis (~> 5)
rubocop-rails-omakase
scrypt (~> 3)
selenium-webdriver
sentry-rails
skylight
solid_cache (~> 1)
solid_queue (~> 1)
spring
spring-watcher-listen
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ In favor of
- [Bootstrap](https://github.com/twbs/bootstrap)
- [FontAwesome](https://github.com/FortAwesome/font-awesome-sass)
- [Rails Authentication Generator](https://www.bigbinary.com/blog/rails-8-introduces-a-basic-authentication-generator)
- [Solid Cache](https://github.com/rails/solid_cache)
- [Solid Queue](https://github.com/rails/solid_queue)

In favor of services
Expand Down
7 changes: 2 additions & 5 deletions config/cable.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
development:
adapter: redis
url: redis://localhost:6379/1
adapter: async

test:
adapter: test

production:
adapter: redis
url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
channel_prefix: rails_skeleton_production
adapter: async
16 changes: 16 additions & 0 deletions config/cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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:
database: cache
<<: *default
8 changes: 8 additions & 0 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ development:
primary: &primary_development
<<: *default
database: rails_skeleton_development
cache:
<<: *primary_development
database: rails_skeleton_development_cache
migrations_paths: db/cache_migrate
queue:
<<: *primary_development
database: rails_skeleton_development_queue
Expand Down Expand Up @@ -89,6 +93,10 @@ production:
database: rails_skeleton_production
username: rails_skeleton
password: <%= ENV["RAILS_SKELETON_DATABASE_PASSWORD"] %>
cache:
<<: *primary_production
database: rails_skeleton_production_cache
migrations_paths: db/cache_migrate
queue:
<<: *primary_production
database: rails_skeleton_production_queue
Expand Down
3 changes: 2 additions & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
config.active_support.report_deprecations = false

# Replace the default in-process memory cache store with a durable alternative.
# config.cache_store = :mem_cache_store
config.cache_store = :solid_cache_store
config.solid_cache.connects_to = { database: { writing: :cache } }

# Replace the default in-process and non-durable queuing backend for Active Job.
config.active_job.queue_adapter = :solid_queue
Expand Down
14 changes: 14 additions & 0 deletions db/cache_schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

ActiveRecord::Schema[7.2].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

0 comments on commit 5737355

Please sign in to comment.