Skip to content

Commit

Permalink
chore: Set up solid cache
Browse files Browse the repository at this point in the history
  • Loading branch information
mromulus committed Nov 12, 2024
1 parent 02a1473 commit 4f2471d
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 50 deletions.
5 changes: 1 addition & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@ gem 'friendly_id', '~> 5.5.0'
gem 'nilify_blanks', '~> 1.4'
gem 'solid_cable'
gem 'solid_queue'
gem 'solid_cache'

# frontend
gem 'haml-rails', '~> 2.0'
gem 'turbo-rails', '~> 2.0'
gem 'view_component'

# TO BE REMOVED
gem 'redis'
gem 'hiredis', '~> 0.6.3'

# functionality
gem 'stringex', '~> 2.8', require: 'stringex_lite'
gem 'http', '~> 5.0'
Expand Down
12 changes: 5 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ GEM
haml (>= 4.0.6)
railties (>= 5.1)
hashie (5.0.0)
hiredis (0.6.3)
http (5.2.0)
addressable (~> 2.8)
base64 (~> 0.1)
Expand Down Expand Up @@ -377,10 +376,6 @@ GEM
rdoc (6.7.0)
psych (>= 4.0.0)
redcarpet (3.6.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 @@ -469,6 +464,10 @@ GEM
activejob (>= 7.2)
activerecord (>= 7.2)
railties (>= 7.2)
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 @@ -559,7 +558,6 @@ DEPENDENCIES
flamegraph
friendly_id (~> 5.5.0)
haml-rails (~> 2.0)
hiredis (~> 0.6.3)
http (~> 5.0)
ipaddress!
kaminari
Expand All @@ -582,7 +580,6 @@ DEPENDENCIES
rails-patterns
rails-pg-extras
redcarpet
redis
rgl
rouge
rspec-rails
Expand All @@ -592,6 +589,7 @@ DEPENDENCIES
silencer
simple_form (~> 5.3)
solid_cable
solid_cache
solid_queue
sqlite3
stackprof
Expand Down
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ console: .makerc-vars ## Open rails console
logs: .makerc-vars ## Tail all logs
$(SUDO_COMMAND) docker compose -f docker/$(DEPLOY_ENVIRONMENT)/docker-compose.yml logs -f --tail=100

clear-redis: .makerc-vars ## Clear rails cache (by flushing redis)
$(SUDO_COMMAND) docker compose -f docker/$(DEPLOY_ENVIRONMENT)/docker-compose.yml exec redis redis-cli flushdb
clear-redis: clear-cache # dummy until migrated

clear-cache: .makerc-vars ## Clear rails cache
$(SUDO_COMMAND) docker compose -f docker/$(DEPLOY_ENVIRONMENT)/docker-compose.yml exec web bin/rails r 'Rails.cache.clear'

import-db:
$(SUDO_COMMAND) docker compose -f docker/$(DEPLOY_ENVIRONMENT)/docker-compose.yml up -d postgresql --wait
Expand All @@ -50,4 +52,4 @@ CURRENT_VERSION:
.makerc-vars:
@echo "\033[93m[*] Configuration file missing, running configurator\033[0m"
@python3 scripts/generate_config.py
@if [ -f ".makerc-vars" ]; then echo "\033[92m[*] Config file created, please rerun the task!\033[0m"; false; else echo "\033[91m[*] Config file was not created, please rerun the task!\033[0m"; false; fi
@if [ -f ".makerc-vars" ]; then echo "\033[92m[*] Config file created, please rerun the task!\033[0m"; false; else echo "\033[91m[*] Config file was not created, please rerun the task!\033[0m"; false; fi
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ Providentia is a [Ruby on Rails](https://github.com/rails/rails) based web appli

Can be switched to any OpenID Connect provider

- ~~Redis~~[Garnet](https://github.com/microsoft/garnet) for caching and session storage
- [PostgreSQL](https://www.postgresql.org/)
- [Rails](https://github.com/rails/rails) app
- [Caddy](https://github.com/caddyserver/caddy) reverse proxy
Expand Down
17 changes: 17 additions & 0 deletions config/cache.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
config.action_controller.perform_caching = false
end

config.cache_store = :redis_cache_store, { url: ENV.fetch('REDIS_URL') { 'redis://localhost:6379/1' } }
config.cache_store = :solid_cache_store

# Store uploaded files on the local file system (see config/storage.yml for options).
config.active_storage.service = :local
Expand Down
10 changes: 1 addition & 9 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,7 @@
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 = :redis_cache_store, {
url: ENV.fetch('REDIS_URL') { 'redis://localhost:6379/0' },

connect_timeout: 30,
read_timeout: 0.2,
write_timeout: 0.2,
reconnect_attempts: 1
}
config.cache_store = :solid_cache_store

# 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
17 changes: 0 additions & 17 deletions docker/dev/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,9 @@ services:
- KEYCLOAK_AVAILABILITYCHECK_TIMEOUT=30s
- IMPORT_FILES='/config/*'

redis:
image: "redis:alpine"
volumes:
- "redis:/data"

garnet:
image: "ghcr.io/microsoft/garnet"
ulimits:
memlock: -1
volumes:
- garnetdata:/data

web:
depends_on:
- "postgresql"
- "redis"
- "garnet"
build:
context: ../../
dockerfile: Dockerfile
Expand Down Expand Up @@ -114,7 +100,6 @@ services:
VITE_RUBY_PORT: 80
VITE_RUBY_SKIP_PROXY: true
DATABASE_URL: postgres://providentia:secret@postgresql/providentia?pool=5
REDIS_URL: redis://garnet:6379/0
OIDC_ISSUER: http://keycloak.localhost/realms/Providentia
OIDC_CLIENT_ID: Providentia
OIDC_CLIENT_SECRET: 00000000-0000-0000-0000-000000000000
Expand Down Expand Up @@ -173,7 +158,5 @@ services:

volumes:
caddy_data:
redis:
postgres_providentia:
postgres_keycloak:
garnetdata:
8 changes: 0 additions & 8 deletions docker/prod/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,9 @@ services:
env_file:
- db.env

redis:
image: "redis:alpine"
restart: unless-stopped
volumes:
- "redis:/data"

web:
depends_on:
- "db"
- "redis"
build:
context: ../../
dockerfile: Dockerfile
Expand Down Expand Up @@ -90,6 +83,5 @@ services:
- IMPORT_FILES='/config/*'

volumes:
redis: {}
caddy_data: {}
providentia_db: {}

0 comments on commit 4f2471d

Please sign in to comment.