Skip to content

Commit 0bb377c

Browse files
committed
Default caching for api_public endpoints
1 parent 4ea4b4e commit 0bb377c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

app/controllers/api_public/v1/base_controller.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,22 @@ module ApiPublic
22
module V1
33
class BaseController < ActionController::Base
44
include SubdomainTenant
5+
56
skip_before_action :verify_authenticity_token
7+
8+
# Set HTTP cache headers and conditional GET for all api_public endpoints
9+
before_action :set_api_public_cache_headers
10+
11+
private
12+
13+
def set_api_public_cache_headers
14+
expires_in 5.hours, public: true
15+
# Conditional GET: Use a generic last-modified time (can be overridden in child controllers)
16+
return unless respond_to?(:resource_last_modified, true)
17+
18+
last_modified = resource_last_modified
19+
fresh_when(last_modified: last_modified) if last_modified
20+
end
621
end
722
end
823
end

0 commit comments

Comments
 (0)