Skip to content

Commit

Permalink
Merge pull request #640 from ChicagoWorldcon/stag-conclar-cacching
Browse files Browse the repository at this point in the history
PLAN-727 cache for conclar requests (2.0.1)
  • Loading branch information
Gailbear authored Aug 17, 2022
2 parents a5b41f7 + 6fb2390 commit d885b58
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 25 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gem 'rails', '~> 6.1' #, '>= 6.0.3.2'
gem 'pg', '>= 0.18', '< 2.0'

gem 'activerecord-postgres_enum'
gem 'actionpack-action_caching'

# Use Puma as the app server
gem 'puma', '>= 5.0'
Expand Down
49 changes: 26 additions & 23 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GEM
remote: https://rubygems.org/
specs:
aasm (5.2.0)
aasm (5.3.0)
concurrent-ruby (~> 1.0)
actioncable (6.1.6.1)
actionpack (= 6.1.6.1)
Expand Down Expand Up @@ -29,6 +29,8 @@ GEM
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actionpack-action_caching (1.2.2)
actionpack (>= 4.0.0)
actiontext (6.1.6.1)
actionpack (= 6.1.6.1)
activerecord (= 6.1.6.1)
Expand Down Expand Up @@ -77,9 +79,9 @@ GEM
ast (2.4.2)
bcrypt (3.1.18)
bindex (0.8.1)
bootsnap (1.12.0)
bootsnap (1.13.0)
msgpack (~> 1.2)
brakeman (5.2.3)
brakeman (5.3.1)
builder (3.2.4)
bundler-audit (0.9.1)
bundler (>= 1.2.0, < 3)
Expand Down Expand Up @@ -115,7 +117,7 @@ GEM
em-websocket (0.5.3)
eventmachine (>= 0.12.9)
http_parser.rb (~> 0)
erubi (1.10.0)
erubi (1.11.0)
et-orbi (1.2.7)
tzinfo
eventmachine (1.2.7)
Expand All @@ -124,7 +126,7 @@ GEM
factory_bot_rails (6.2.0)
factory_bot (~> 6.2.0)
railties (>= 5.0.0)
faker (2.21.0)
faker (2.22.0)
i18n (>= 1.8.11, < 2)
fast_excel (0.4.0)
ffi (> 1.9, < 2)
Expand Down Expand Up @@ -190,32 +192,32 @@ GEM
method_source (1.0.0)
mini_mime (1.1.2)
mini_portile2 (2.8.0)
minitest (5.16.2)
msgpack (1.5.3)
minitest (5.16.3)
msgpack (1.5.4)
multi_json (1.15.0)
nenv (0.3.0)
nilify_blanks (1.4.0)
activerecord (>= 4.0.0)
activesupport (>= 4.0.0)
nio4r (2.5.8)
nokogiri (1.13.7)
nokogiri (1.13.8)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
nokogiri (1.13.7-x86_64-darwin)
nokogiri (1.13.8-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.13.7-x86_64-linux)
nokogiri (1.13.8-x86_64-linux)
racc (~> 1.4)
notiffany (0.1.3)
nenv (~> 0.1)
shellany (~> 0.0)
orm_adapter (0.5.0)
paper_trail (12.3.0)
paper_trail (13.0.0)
activerecord (>= 5.2)
request_store (~> 1.1)
parallel (1.22.1)
parser (3.1.2.0)
parser (3.1.2.1)
ast (~> 2.4.1)
pg (1.4.1)
pg (1.4.3)
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
Expand Down Expand Up @@ -304,17 +306,17 @@ GEM
rspec-mocks (~> 3.10)
rspec-support (~> 3.10)
rspec-support (3.11.0)
rubocop (1.31.2)
rubocop (1.35.0)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.1.0.0)
parser (>= 3.1.2.1)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.18.0, < 2.0)
rubocop-ast (>= 1.20.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.19.1)
rubocop-ast (1.21.0)
parser (>= 3.1.1.0)
ruby-progressbar (1.11.0)
ruby_audit (2.1.0)
Expand All @@ -334,17 +336,17 @@ GEM
tilt
seedbank (0.5.0)
rake (>= 10.0)
selenium-webdriver (4.3.0)
selenium-webdriver (4.4.0)
childprocess (>= 0.5, < 5.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
semantic_range (3.0.0)
shellany (0.0.1)
sidekiq (6.5.1)
sidekiq (6.5.4)
connection_pool (>= 2.2.2)
rack (~> 2.0)
redis (>= 4.2.0)
redis (>= 4.5.0)
sidekiq-scheduler (4.0.2)
redis (>= 4.2.0)
rufus-scheduler (~> 3.2)
Expand All @@ -364,10 +366,10 @@ GEM
activesupport (>= 5.2)
sprockets (>= 3.0.0)
thor (1.2.1)
tilt (2.0.10)
truemail (2.7.3)
tilt (2.0.11)
truemail (2.7.4)
simpleidn (~> 0.2.1)
tzinfo (2.0.4)
tzinfo (2.0.5)
concurrent-ruby (~> 1.0)
unf (0.1.4)
unf_ext
Expand Down Expand Up @@ -407,6 +409,7 @@ PLATFORMS

DEPENDENCIES
aasm
actionpack-action_caching
active_model_serializers (~> 0.10.0)
activerecord-postgres_enum
acts-as-taggable-on (~> 9.0)
Expand Down
11 changes: 11 additions & 0 deletions app/controllers/schedule_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
class ScheduleController < ApplicationController
skip_before_action :check_up, :authenticate_person!, only: [:index, :participants]

# Put in a memory cache and cache header for the conclar data
before_action :setup_cache_header

# Cache index and particpant request for 10 minutes and prevent dog pile by allowing 1 minute regen
caches_action :index, expires_in: 10.minute, race_condition_ttl: 1.minute
caches_action :participants, expires_in: 10.minute, race_condition_ttl: 1.minute

# 1. If prod always use the published schedule
# 2. If staging or dev use published - if no published then use the live for testing
# 3. cache mechanism (cache can be popultaed as part of the publish)
Expand Down Expand Up @@ -35,4 +42,8 @@ def participants
content_type: 'application/json'
end
end

def setup_cache_header
response.headers["Cache-Control"] = "public, max-age=#{10.minutes.to_i}"
end
end
2 changes: 1 addition & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
config.log_tags = [ :request_id ]

# Use a different cache store in production.
# config.cache_store = :mem_cache_store
config.cache_store = :mem_cache_store

# Use a real queuing backend for Active Job (and separate queues per environment).
config.active_job.queue_adapter = :sidekiq
Expand Down
2 changes: 1 addition & 1 deletion config/environments/staging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
config.log_tags = [ :request_id ]

# Use a different cache store in staging.
# config.cache_store = :mem_cache_store
config.cache_store = :mem_cache_store

# Use a real queuing backend for Active Job (and separate queues per environment).
config.active_job.queue_adapter = :sidekiq
Expand Down

0 comments on commit d885b58

Please sign in to comment.