diff --git a/app/controllers/api/v1/accounts_controller.rb b/app/controllers/api/v1/accounts_controller.rb index 5af8a1fd1..ef0e0c777 100644 --- a/app/controllers/api/v1/accounts_controller.rb +++ b/app/controllers/api/v1/accounts_controller.rb @@ -37,6 +37,7 @@ class Api::V1::AccountsController < Api::BaseController end def cache_keys + expires_in 10.seconds, public: false, stale_while_revalidate: 5.minutes render json: { cache_keys: get_cache_keys }, status: :ok end diff --git a/spec/controllers/api/v1/accounts_controller_spec.rb b/spec/controllers/api/v1/accounts_controller_spec.rb index 6b21cfbb2..ce5f9623c 100644 --- a/spec/controllers/api/v1/accounts_controller_spec.rb +++ b/spec/controllers/api/v1/accounts_controller_spec.rb @@ -151,6 +151,16 @@ RSpec.describe 'Accounts API', type: :request do expect(response).to have_http_status(:success) expect(response.parsed_body['cache_keys'].keys).to match_array(%w[label inbox team]) end + + it 'sets the appropriate cache headers' do + get "/api/v1/accounts/#{account.id}/cache_keys", + headers: admin.create_new_auth_token, + as: :json + + expect(response.headers['Cache-Control']).to include('max-age=10') + expect(response.headers['Cache-Control']).to include('private') + expect(response.headers['Cache-Control']).to include('stale-while-revalidate=300') + end end describe 'PUT /api/v1/accounts/{account.id}' do