https://github.com/staabm/http-cache-control
http cache-control tools, to ease http handling for common caching use-cases
https://github.com/staabm/http-cache-control
Last synced: about 1 year ago
JSON representation
http cache-control tools, to ease http handling for common caching use-cases
- Host: GitHub
- URL: https://github.com/staabm/http-cache-control
- Owner: staabm
- Created: 2022-04-11T08:18:26.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-04-11T12:59:48.000Z (about 4 years ago)
- Last Synced: 2025-03-05T10:45:33.459Z (over 1 year ago)
- Language: PHP
- Size: 5.86 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Http-Cache-Control
------------------
A tiny lib which provides documented [constants](https://github.com/staabm/http-cache-control/blob/main/lib/Constants.php) and [example use-cases](https://github.com/staabm/http-cache-control/blob/main/lib/UseCase.php) for the HTTP `Cache-Control` header, based on the [official cloudflare documentation](https://developers.cloudflare.com/cache/about/cache-control/).
Sending proper Cache-Control headers is essential to each web-application, but the required keywords are sometimes misleading and ambiguous.
This library aims to provide a more reliable and consistent way to set the Cache-Control header.
Example
-------
```php
use staabm\HttpCacheControl\Constants;
use staabm\HttpCacheControl\UseCase;
class MyController {
public function sendPdf(string $pdfFile) {
header(Constants::CACHE_CONTROL .':'. UseCase::cacheOnBrowserAndProxyRequireProxyRevalidation());
readfile($pdfFile);
}
public function sendGdpr(string $pdfFile) {
header(Constants::CACHE_CONTROL_CLOUDFLARE .':'. UseCase::cacheOnBrowserAndProxyForDifferentTime(300, 3600));
readfile($pdfFile);
}
}
```