slim/http-cache
A PSR-15 middleware that adds HTTP caching to Slim 4 apps, handling ETag/Last-Modified conditional requests, Cache-Control headers, and filesystem response caching to cut bandwidth and speed up repeat visits.
Cache-Control, Expires, ETag, and Last-Modified headers and honor If-None-Match / If-Modified-Since with a 304 Not Modified — the cheapest latency and bandwidth win available before we invest in a CDN, Redis, or an edge tier.Vary, 304 body stripping) that are easy to get wrong and hard to test.slim/http-cache is not a Laravel package. It is PSR-7/PSR-15 middleware (plus a Pimple service provider for Slim 3) for the Slim Framework. For a Laravel codebase the decision it supports is "use a Laravel-native equivalent" (spatie/laravel-responsecache, Symfony's HttpCache, or framework middleware), with this package serving only as a reference implementation of the header semantics. For a Slim-based microservice or internal API in our estate, it is directly adoptable.slimphp org under MIT — but it does mean we, not the community, will be the ones finding the edge cases.Adopt when all of the following hold:
Vary for anything content-negotiated.Look elsewhere when:
spatie/laravel-responsecache, Laravel's own cache middleware, or Symfony HttpCache/HttpKernel — anything else means re-implementing the integration and owning it forever.Vary/private handling the middleware creates more risk than it removes.stale-while-revalidate, stale-if-error, surrogate keys. Reach for a CDN or dedicated cache layer instead.To executives: This is a small, MIT-licensed middleware from the official Slim project that lets our read APIs answer "has this changed?" with a cheap 304 instead of a full payload. It requires no new infrastructure, cuts bandwidth and mobile latency on our most-repeated GET calls, and is roughly a few hundred lines we can read, test, and fork if needed. The honest framing: the wins are real but incremental, and it only applies to services built on Slim — for our Laravel services we would standardize on the Laravel-native equivalent and treat this as the reference pattern. It is a tactical optimization, not a platform investment, and it should not be sold as a substitute for a CDN.
To engineering: Thin PSR-15 middleware (PSR-7 for Slim 3) that adds Cache-Control, Expires, ETag, Last-Modified and returns 304 on conditional requests; it handles header semantics only — no response storage, no invalidation, no tagging — so pair it with explicit cache policy per route and careful Vary handling for anything personalized. Low community adoption (116 stars, 0 dependents), so budget for reading the source, adding our own test coverage on ETag stability and 304 body handling, and accepting that we may vendor it. Adopt on Slim services with clearly cacheable GET endpoints; do not introduce it into Laravel, and do not use it as a stand-in for a CDN or response cache.
How can I help you explore Laravel packages today?