Skip to content

Commit

Permalink
Merge #2342
Browse files Browse the repository at this point in the history
2342: Cache the API root endpoint for longer. r=tiftran a=smarnach

The information at the API root endpoints virtually never changes; it's just a list of endpoints in the API  with no dynamic information. At the same time, it's the endpoint we get by far the most requests for. We can reduce the load on the origin servers considerably if we cache this endpoint for a whole day instead of just 30 seconds.

Co-authored-by: Sven Marnach <sven@mozilla.com>
  • Loading branch information
bors[bot] and smarnach authored Dec 2, 2022
2 parents 2e9f25a + 53192d6 commit 6bc988d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/ops/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,13 @@ in other Django projects.
set to 0 in non-production environments to ease testing. In production
environments, setting this value too low can be a denial-of-service risk.

.. envvar:: DJANGO_API_ROOT_CACHE_TIME

:default: ``86400`` (1 day)

The time in seconds to set in cache headers for cacheable API root
endpoints.

.. envvar:: DJANGO_API_CACHE_ENABLED

:default: ``True``
Expand Down
2 changes: 1 addition & 1 deletion normandy/base/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class APIRootView(APIView):
exclude_from_schema = True
urlconf = None

@api_cache_control(max_age=settings.API_CACHE_TIME)
@api_cache_control(max_age=settings.API_ROOT_CACHE_TIME)
def get(self, request, *args, **kwargs):
ret = {}

Expand Down
2 changes: 2 additions & 0 deletions normandy/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ def RAVEN_CONFIG(self):
ADMIN_ENABLED = values.BooleanValue(True)
IMMUTABLE_CACHE_TIME = values.IntegerValue(60 * 60 * 24 * 365)
NUM_PROXIES = values.IntegerValue(0)
API_ROOT_CACHE_TIME = values.IntegerValue(60 * 60 * 24)
API_CACHE_TIME = values.IntegerValue(30)
API_CACHE_ENABLED = values.BooleanValue(True)
PERMANENT_REDIRECT_CACHE_TIME = values.IntegerValue(60 * 60 * 24 * 30)
Expand Down Expand Up @@ -440,6 +441,7 @@ class Development(InsecureAuthentication, Base):
DEFAULT_FILE_STORAGE = values.Value("django.core.files.storage.FileSystemStorage")

API_CACHE_ENABLED = values.BooleanValue(False)
API_ROOT_CACHE_TIME = values.IntegerValue(0)
API_CACHE_TIME = values.IntegerValue(0)

SILENCED_SYSTEM_CHECKS = values.ListValue(["normandy.recipes.E006"]) # geoip db not available
Expand Down

0 comments on commit 6bc988d

Please sign in to comment.