PHPackages                             smartondev/httpcache-middleware - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. smartondev/httpcache-middleware

ActiveLibrary[HTTP &amp; Networking](/categories/http)

smartondev/httpcache-middleware
===============================

PSR-7, PSR-11 compatible middlewares for HTTP cache handling

02PHP

Since Nov 2Pushed 1y ago1 watchersCompare

[ Source](https://github.com/smartondev/httpcache-middleware)[ Packagist](https://packagist.org/packages/smartondev/httpcache-middleware)[ RSS](/packages/smartondev-httpcache-middleware/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

HTTP cache header middlewares for PSR-7, PSR-11
===============================================

[](#http-cache-header-middlewares-for-psr-7-psr-11)

**This package is under development, and not ready for production use.**

This package provides a set (eg. Cache-Control, ETag) of HTTP cache handling PSR-7, PSR-11 compatible middlewares.

Installation
------------

[](#installation)

```
composer require smartondev/httpcache-middleware
```

Usage
-----

[](#usage)

### Cache-Control

[](#cache-control)

For use `Cache-Control`, `ETag`, `Last-Modified` and more http "caching" headers, you need to add `HttpCacheMiddleware`to your route.

```
use SmartonDev\HttpCacheMiddleware\Http\Middleware\HttpCacheMiddleware;
use SmartonDev\HttpCacheMiddleware\Providers\Constants\ProviderConstants;

// add HttpCacheContextService to container with ProviderConstants::HTTP_CACHE_CONTEXT_SERVICE_ID as singleton per request

Route::get('/api/user/{id}', function ($id) {
    $user = User::find($id);
    app()->get(ProviderConstants::HTTP_CACHE_CONTEXT_SERVICE_ID)->getCacheHeaderBuilder()->maxAge(days: 30)->public();
    return response()->json($user);
})->middleware(HttpCacheMiddleware::class);
```

### ETag

[](#etag)

For use ETag, you need to add `ETagMatchMiddleware` to your route. You need to implement `ETagResolverInterface` and add it to the container with `ProviderConstants::ETAG_RESOLVER_SERVICE_ID`. For use ETag you need to add `HttpCacheContextService` and`HttpCacheMiddleware` to the container with `ProviderConstants::HTTP_CACHE_CONTEXT_SERVICE_ID`and `ProviderConstants::HTTP_CACHE_MIDDLEWARE_SERVICE_ID`.

```
use SmartonDev\HttpCacheMiddleware\Http\Middleware\ETagMatchMiddleware;
use SmartonDev\HttpCacheMiddleware\Http\Middleware\HttpCacheMiddleware;
use SmartonDev\HttpCacheMiddleware\Providers\Constants\ProviderConstants;
use SmartonDev\HttpCacheMiddleware\Contracts\ETagResolverInterface;

class ETagResolver implements ETagResolverInterface
{
    public function resolve($request): string
    {
        // use it own logic to generate ETag
        $id = $request->route('id');
        $etagFromCache = Cache::get('etag_' . $id);
        return $etagFromCache;
    }
}
// add ETagResolver to container with ProviderConstants::ETAG_RESOLVER_SERVICE_ID
// add HttpCacheContextService to container with ProviderConstants::HTTP_CACHE_CONTEXT_SERVICE_ID as singleton pre request

Route::get('/api/user/{id}', function ($id) {
    $user = User::find($id);
    app()->get(ProviderConstants::HTTP_CACHE_CONTEXT_SERVICE_ID)->getCacheHeaderBuilder()->maxAge(days: 30)->public();
    // etag added automatically, or you can set it manually
    return response()->json($user);
})->middleware(HttpCacheMiddleware::class)->middleware(ETagMatchMiddleware::class);
```

### Modified since

[](#modified-since)

```
```

Author
------

[](#author)

- [Márton Somogyi](https://github.com/kamarton)

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity16

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/8a752abf82b63be991429512fd0f95260532868511626d6aab9a9891b6177d6e?d=identicon)[smartondev](/maintainers/smartondev)

---

Top Contributors

[![kamarton](https://avatars.githubusercontent.com/u/9432032?v=4)](https://github.com/kamarton "kamarton (7 commits)")

### Embed Badge

![Health badge](/badges/smartondev-httpcache-middleware/health.svg)

```
[![Health](https://phpackages.com/badges/smartondev-httpcache-middleware/health.svg)](https://phpackages.com/packages/smartondev-httpcache-middleware)
```

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M319](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M293](/packages/pusher-pusher-php-server)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78026.4M414](/packages/react-http)[php-http/curl-client

PSR-18 and HTTPlug Async client with cURL

48347.0M384](/packages/php-http-curl-client)[smi2/phpclickhouse

PHP ClickHouse Client

84310.1M71](/packages/smi2-phpclickhouse)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
