switon / http-cache
Redis-backed per-action HTTP caching with request-derived keys and ETag revalidation for Switon Framework
v1.0.0
2026-06-06 13:43 UTC
Requires
- php: >=8.3
- switon/core: ^1.0
- switon/event: ^1.0
- switon/http: ^1.0
- switon/redis: ^1.0
Requires (Dev)
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.0
- switon/testing: ^1.0
README
Switon's page cache filter for Redis-backed action caching and conditional HTTP responses.
Highlights
- Action-level page cache:
#[PageCache]marks controller actions cacheable with a TTL. - Redis-backed storage: cached responses are stored in Redis.
- Request-aware keys: keys can use selected request fields or fixed values.
- Conditional responses: cache hits can still support
304 Not Modified. - Scoped lookup: cache lookup applies only to eligible request methods.
Installation
composer require switon/http-cache
Quick Start
use Switon\HttpCache\Attribute\PageCache; use Switon\Routing\Attribute\GetMapping; class ProductController { #[GetMapping('/products')] #[PageCache(ttl: 600, key: ['category', 'page'])] public function listAction(string $category = 'all', int $page = 1): array { return [ 'category' => $category, 'page' => $page, 'items' => $this->loadProducts($category, $page), ]; } }
Docs: https://docs.switon.dev/latest/http-cache
License
MIT.