Skip to content

Commit

Permalink
Merge pull request #345 from blackcandy-org/solid-cache
Browse files Browse the repository at this point in the history
Replace litecache with solid_cache
  • Loading branch information
aidewoode authored Feb 2, 2024
2 parents c7dff0e + b2cfa72 commit f29e01c
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ gem "puma", "~> 6.4.0"
# Default database
gem "sqlite3", "~> 1.7.0"

# Cache store
gem "solid_cache", "~> 0.4.2"

# Background job processing
gem "solid_queue", "~> 0.2.1"

Expand Down
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ GEM
simplecov-lcov (0.8.0)
simplecov_json_formatter (0.1.4)
smart_properties (1.17.0)
solid_cache (0.4.2)
activejob (>= 7)
activerecord (>= 7)
railties (>= 7)
solid_queue (0.2.1)
rails (~> 7.1)
sqlite3 (1.7.0)
Expand Down Expand Up @@ -416,6 +420,7 @@ DEPENDENCIES
sidekiq (~> 7.1.2)
simplecov (~> 0.22.0)
simplecov-lcov (~> 0.8.0)
solid_cache (~> 0.4.2)
solid_queue (~> 0.2.1)
sqlite3 (~> 1.7.0)
standard (~> 1.25.0)
Expand Down
2 changes: 1 addition & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
config.action_controller.perform_caching = true
config.action_controller.enable_fragment_cache_logging = true

config.cache_store = :memory_store
config.cache_store = :solid_cache_store
config.public_file_server.headers = {
"Cache-Control" => "public, max-age=#{2.days.to_i}"
}
Expand Down
2 changes: 1 addition & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info")

# Use a different cache store in production.
config.cache_store = BlackCandy::Config.redis_cache_url.present? ? [:redis_cache_store, {url: BlackCandy::Config.redis_cache_url}] : [:litecache, {path: "storage/production_cache.sqlite3"}]
config.cache_store = BlackCandy::Config.redis_cache_url.present? ? [:redis_cache_store, {url: BlackCandy::Config.redis_cache_url}] : :solid_cache_store

# Use a real queuing backend for Active Job (and separate queues per environment).
config.active_job.queue_adapter = BlackCandy::Config.redis_sidekiq_url.present? ? :sidekiq : :solid_queue
Expand Down
2 changes: 1 addition & 1 deletion config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.cache_store = :memory_store
config.cache_store = :solid_cache_store

# Raise exceptions instead of rendering exception templates.
config.action_dispatch.show_exceptions = :rescuable
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This migration comes from solid_cache (originally 20230724121448)
class CreateSolidCacheEntries < ActiveRecord::Migration[7.0]
def change
create_table :solid_cache_entries do |t|
t.binary :key, null: false, limit: 1024
t.binary :value, null: false, limit: 512.megabytes
t.datetime :created_at, null: false

t.index :key, unique: true
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This migration comes from solid_cache (originally 20240108155507)
class AddKeyHashAndByteSizeToSolidCacheEntries < ActiveRecord::Migration[7.1]
def change
change_table :solid_cache_entries do |t|
t.column :key_hash, :integer, null: true, limit: 8
t.column :byte_size, :integer, null: true, limit: 4
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This migration comes from solid_cache (originally 20240110111600)
class AddKeyHashAndByteSizeIndexesAndNullConstraintsToSolidCacheEntries < ActiveRecord::Migration[7.1]
def change
change_table :solid_cache_entries, bulk: true do |t|
t.change_null :key_hash, false
t.change_null :byte_size, false
t.index :key_hash, unique: true
t.index [:key_hash, :byte_size]
t.index :byte_size
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This migration comes from solid_cache (originally 20240110111702)
class RemoveKeyIndexFromSolidCacheEntries < ActiveRecord::Migration[7.1]
def change
change_table :solid_cache_entries do |t|
t.remove_index :key, unique: true
end
end
end
13 changes: 12 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2024_01_22_024820) do
ActiveRecord::Schema[7.1].define(version: 2024_02_02_024633) do
create_table "active_storage_attachments", force: :cascade do |t|
t.string "name", null: false
t.string "record_type", null: false
Expand Down Expand Up @@ -91,6 +91,17 @@
t.index ["singleton_guard"], name: "index_settings_on_singleton_guard", unique: true
end

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

create_table "solid_queue_blocked_executions", force: :cascade do |t|
t.integer "job_id", null: false
t.string "queue_name", null: false
Expand Down

0 comments on commit f29e01c

Please sign in to comment.