Skip to content

Commit

Permalink
Merge pull request #81 from AlchemyCMS/configure-ttl-in-secondes
Browse files Browse the repository at this point in the history
Do not convert cache duration to hours
  • Loading branch information
tvdeyen authored May 15, 2024
2 parents 7b1d334 + ae5602b commit 19af451
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/controllers/alchemy/json_api/nodes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Alchemy
module JsonApi
class NodesController < JsonApi::BaseController
THREE_HOURS = 10800

def index
@nodes = node_scope.select(:id, :updated_at)
if stale?(last_modified: @nodes.maximum(:updated_at), etag: @nodes)
Expand All @@ -17,7 +19,7 @@ def index
private

def cache_duration
ENV.fetch("ALCHEMY_JSON_API_CACHE_DURATION", 3).to_i.hours
ENV.fetch("ALCHEMY_JSON_API_CACHE_DURATION", THREE_HOURS).to_i
end

def jsonapi_meta(nodes)
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/alchemy/json_api/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Alchemy
module JsonApi
class PagesController < JsonApi::BaseController
THREE_HOURS = 10800

before_action :load_page_for_cache_key, only: :show

def index
Expand Down Expand Up @@ -47,7 +49,7 @@ def render_pages_json(allowed)
end

def cache_duration
ENV.fetch("ALCHEMY_JSON_API_CACHE_DURATION", 3).to_i.hours
ENV.fetch("ALCHEMY_JSON_API_CACHE_DURATION", THREE_HOURS).to_i
end

def caching_options
Expand Down

0 comments on commit 19af451

Please sign in to comment.