staabm/http-cache-control

A tiny lib which provides documented constants and example use-cases for the HTTP Cache-Control header.

1.0 2022-04-11 11:55 UTC

This package is auto-updated.

Last update: 2024-12-11 19:36:00 UTC


README

A tiny lib which provides documented constants and example use-cases for the HTTP Cache-Control header, based on the official cloudflare documentation.

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

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);
    }
}