PHPackages                             devouted/symfony-as-cached-attribute - 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. [Caching](/categories/caching)
4. /
5. devouted/symfony-as-cached-attribute

ActiveLibrary[Caching](/categories/caching)

devouted/symfony-as-cached-attribute
====================================

About

1.1.0(1mo ago)015MITPHPPHP ^8.2

Since Feb 9Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/devouted/symfony-as-cached-attribute)[ Packagist](https://packagist.org/packages/devouted/symfony-as-cached-attribute)[ RSS](/packages/devouted-symfony-as-cached-attribute/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (38)Versions (12)Used By (0)

AsCachedAttribute
=================

[](#ascachedattribute)

Symfony attribute-based HTTP response caching. Mark controller actions with `#[AsCachedResponse]` to automatically cache responses.

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

[](#installation)

```
composer require devouted/symfony-as-cached-attribute
```

Usage
-----

[](#usage)

### Service configuration

[](#service-configuration)

Add to your `services.yaml`:

```
services:
  Devouted\AsCachedAttribute\Listener\CachedResponseListener:
    arguments:
      $cache: '@cache.app'
      $logger: '@monolog.logger'          # optional, set to ~ to disable
      $modifyResponseCacheHeaders: true   # optional, set to false to skip Cache-Control headers
    tags:
      - { name: kernel.event_listener, event: kernel.controller_arguments, priority: -1 }
      - { name: kernel.event_listener, event: kernel.response, priority: 1000 }
```

### Basic usage

[](#basic-usage)

```
#[AsCachedResponse]
public function __invoke(): Response
{
    return new Response('cached content');
}
```

or on a regular controller action:

```
#[AsCachedResponse]
public function someAction(Request $request): Response
{
    return new Response('cached content');
}
```

### Cache key parametrization

[](#cache-key-parametrization)

Use `#[AsCachedRequestParameter]` on method parameters or DTO properties to build unique cache keys per request:

On method parameters:

```
#[AsCachedResponse]
public function show(
    #[AsCachedRequestParameter] int $id,
    #[AsCachedRequestParameter] string $slug
): Response {
    return new Response("id={$id}, slug={$slug}");
}
```

On DTO properties (e.g. with `#[MapQueryString]` or `#[MapRequestPayload]`):

```
#[AsCachedResponse]
public function list(#[MapQueryString] ProductFilter $filter): Response
{
    return new Response("filtered list");
}

class ProductFilter
{
    public function __construct(
        #[AsCachedRequestParameter]
        public int $categoryId,
        #[AsCachedRequestParameter]
        public ?string $sort = null,
    ) {}
}
```

### AsCachedResponse options

[](#ascachedresponse-options)

```
#[AsCachedResponse(
    ttl: 3600,           // cache lifetime in seconds (default: 3600)
    etag: 'my-etag',     // optional ETag header value
    expires: 'tomorrow', // optional Expires header (any strtotime-compatible string)
    isPublic: true,      // public (shared) or private cache (default: true)
)]
```

### Response headers

[](#response-headers)

Cached responses include an `X-Cache` header:

- `Miss` — response was generated and stored in cache
- `Hit` — response was served from cache

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance89

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

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.

###  Release Activity

Cadence

Every ~41 days

Recently: every ~0 days

Total

11

Last Release

53d ago

PHP version history (2 changes)v1.0.0PHP ^8.1

1.0.4PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/af14ce65ee6a526c9d7846b537c55f86c2bbb4875a0a5006820f628e854bfa20?d=identicon)[devouted](/maintainers/devouted)

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/devouted-symfony-as-cached-attribute/health.svg)

```
[![Health](https://phpackages.com/badges/devouted-symfony-as-cached-attribute/health.svg)](https://phpackages.com/packages/devouted-symfony-as-cached-attribute)
```

###  Alternatives

[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)[simplesamlphp/simplesamlphp

A PHP implementation of a SAML 2.0 service provider and identity provider.

1.1k12.4M193](/packages/simplesamlphp-simplesamlphp)[nelmio/api-doc-bundle

Generates documentation for your REST API from attributes

2.3k63.6M233](/packages/nelmio-api-doc-bundle)

PHPackages © 2026

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