Skip to content

Commit d11893b

Browse files
committed
Remove fragment caching from advisories index and increase HTTP cache TTL
Drop cached: true from index jbuilder to avoid writing oversized objects to memcached. Increase expires_in from 5 minutes to 1 hour on index, packages, and lookup endpoints.
1 parent e9e2b7a commit d11893b

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

app/controllers/api/v1/advisories_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class Api::V1::AdvisoriesController < Api::V1::ApplicationController
22
def index
3-
expires_in 5.minutes, public: true, stale_while_revalidate: 1.hour
3+
expires_in 1.hour, public: true, stale_while_revalidate: 1.hour
44

55
scope = Advisory.all
66

@@ -32,7 +32,7 @@ def show
3232
end
3333

3434
def packages
35-
expires_in 5.minutes, public: true, stale_while_revalidate: 1.hour
35+
expires_in 1.hour, public: true, stale_while_revalidate: 1.hour
3636

3737
render json: Advisory.packages
3838
end
@@ -58,7 +58,7 @@ def lookup
5858
return
5959
end
6060

61-
expires_in 5.minutes, public: true, stale_while_revalidate: 1.hour
61+
expires_in 1.hour, public: true, stale_while_revalidate: 1.hour
6262

6363
advisories = Advisory.ecosystem(parsed_purl[:ecosystem])
6464
.package_name(parsed_purl[:package_name])
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
json.partial! 'api/v1/advisories/advisory', collection: @advisories, as: :advisory, cached: true
1+
json.partial! 'api/v1/advisories/advisory', collection: @advisories, as: :advisory

test/controllers/api/v1/advisories_controller_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Api::V1::AdvisoriesControllerTest < ActionDispatch::IntegrationTest
2020
test "should get index" do
2121
get api_v1_advisories_url, as: :json
2222
assert_response :success
23-
assert_match /max-age=300/, response.headers["Cache-Control"]
23+
assert_match /max-age=3600/, response.headers["Cache-Control"]
2424
assert_match /public/, response.headers["Cache-Control"]
2525
assert_match /stale-while-revalidate=3600/, response.headers["Cache-Control"]
2626
end
@@ -143,7 +143,7 @@ class Api::V1::AdvisoriesControllerTest < ActionDispatch::IntegrationTest
143143
test "should get packages" do
144144
get packages_api_v1_advisories_url, as: :json
145145
assert_response :success
146-
assert_match /max-age=300/, response.headers["Cache-Control"]
146+
assert_match /max-age=3600/, response.headers["Cache-Control"]
147147
assert_match /public/, response.headers["Cache-Control"]
148148
end
149149

0 commit comments

Comments
 (0)