Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add cache-control headers #31

Open
JohnRDOrazio opened this issue Feb 6, 2022 · 0 comments
Open

add cache-control headers #31

JohnRDOrazio opened this issue Feb 6, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@JohnRDOrazio
Copy link
Member

Seeing the contents requested will not change often, we should add cache-control headers to the JSON resources output by the API. This would probably avoid having to check against IP addresses in an attempt to avoid abusive usage of the API. If the JSON resources are generally cached, with an expiration of say 1 month, this should prevent the server from being bombarded by requests from a same IP or domain.

Example:

header('Cache-Control: must-revalidate, max-age=259200'); //revalidate after one month

Should also include an ETag header, which might allow us to extend the cache even longer. The ETag should contain the hash of the response contents (i.e. the hash of the JSON string). The way stylesheets are often handled for example is by changing a hash in the name of the file when the contents change. Here, not having an actual filename, we can set the ETag header with a hash value which will let the client know if the contents have changed.

$etag = md5( json_encode( $response ) );
header("ETag: \"{$etag}\"");
@JohnRDOrazio JohnRDOrazio added the enhancement New feature or request label Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant