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 15, 2024
1 parent fbb5d31 commit d84608d
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 49 deletions.
5 changes: 1 addition & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@ gem 'nilify_blanks', '~> 1.4'
gem 'data_migrate'
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 @@ -182,7 +182,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 @@ -380,10 +379,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 @@ -472,6 +467,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 @@ -563,7 +562,6 @@ DEPENDENCIES
flamegraph
friendly_id (~> 5.5.0)
haml-rails (~> 2.0)
hiredis (~> 0.6.3)
http (~> 5.0)
ipaddress!
kaminari
Expand All @@ -586,7 +584,6 @@ DEPENDENCIES
rails-patterns
rails-pg-extras
redcarpet
redis
rgl
rouge
rspec-rails
Expand All @@ -596,6 +593,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 @@ -36,8 +36,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 @@ -51,4 +53,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
26 changes: 26 additions & 0 deletions db/cache_schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

# 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
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 @@ -112,7 +98,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 @@ -171,7 +156,5 @@ services:

volumes:
caddy_data:
redis:
postgres_providentia:
postgres_keycloak:
garnetdata:
7 changes: 0 additions & 7 deletions docker/prod/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,6 @@ services:
- POSTGRES_PASSWORD=secret
- POSTGRES_DB=providentia

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

keycloak:
image: bitnami/keycloak:25.0.4
depends_on:
Expand Down Expand Up @@ -98,6 +92,5 @@ services:
- IMPORT_FILES='/config/*'

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

0 comments on commit d84608d

Please sign in to comment.