PHPackages                             paveldanilin/response-cache-bundle - 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. paveldanilin/response-cache-bundle

ActiveSymfony-bundle[Caching](/categories/caching)

paveldanilin/response-cache-bundle
==================================

A Symfony ResponseCache Bundle

3774PHP

Since Feb 2Pushed 4y ago1 watchersCompare

[ Source](https://github.com/paveldanilin/response-cache-bundle)[ Packagist](https://packagist.org/packages/paveldanilin/response-cache-bundle)[ RSS](/packages/paveldanilin-response-cache-bundle/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

A set of Symfony controller cache annotations
=============================================

[](#a-set-of-symfony-controller-cache-annotations)

AnnotationDescription@CacheableIf a key exists in the cache pool and it is not expired returns a cached value instead of a controller action invocation. Otherwise passes to a controller action and puts into the cache pool the result of the invocation.@CacheEvictRemoves a cached value from a cache pool.Install
-------

[](#install)

`composer require paveldanilin/response-cache-bundle`

Configuration
-------------

[](#configuration)

```
# Default values
response_cache:
  lock:
    factory: 'lock.response_cache.factory'
  controller:
    dir: '%kernel.project_dir%/src'
```

`lock.factory`: A lock factory service, [read more](https://symfony.com/doc/current/components/lock.html) about lock component configuration.

`controller.dir`: A controller directory for annotation scan.

Usage
-----

[](#usage)

### @Cacheable

[](#cacheable)

Enables caching behavior for a controller action method.

```
@Cacheable(
    pool="",
    key="",
    ttl="",
    condition=""
)
```

The default parameters:

- `key` - a concatenated class name with a method name: `App\Controller\MyController_doHeavyComputation`
- `pool` - `cache.app`
- `ttl` - null (never gets expired)
- `condition` - null

```
/**
  * @Cacheable()
  * @Route("/api/v1/work", methods={"GET"}, name="do.work")
  * @return JsonResponse
  */
public function doWork(Request $request): JsonResponse
{
    $data = doHeavyComputations();
    return new JsonResponse($data);
}
```

#### Key

[](#key)

There are two types of keys:

- static
- dynamic

**Static key**

The static key is whether an empty value `` or a string `''`.

For example: `@Cacheable()` or `@Cacheable(key='my_item')`

**Dynamic key**

The dynamic key starts from the '#' sign i.e. `#`.

[Symfony expression language](https://symfony.com/doc/current/components/expression_language/syntax.html) is used for the dynamic key computation.

The following variables can be used in the expression:

VariableDescriptionTyperequestInbound request object\\Symfony\\Component\\HttpFoundation\\Requestrequest\_methodHttp request methodstringrequest\_uriRequest URIstringrequest\_localeRequest LocalestringThe functions can be used in the expression:

FunctionDescriptionquery\_val(key, def = '')\* *key* string or array of strings
 \* *def* stringroute\_val(key, def = '')\* *key* string or array of strings
 \* *def* stringbody()Returns a request body contentbody\_json(path, def = '')Decodes a request body as json and returns the path value.Examples:

```
@Cacheable(key="#request.getMethod()~request.getRequestUri()")
```

```
@Cacheable(key="#query_val('id', 'def_value')")
```

```
@Cacheable(key="#query_val(['id', 'x_query_param'])")
```

```
@Cacheable(key="#route_val('id')")
```

```
@Cacheable(key="#route_val(['id', 'x_route_param'])")
```

```
// Request body: {"account": {"id": 123}}
// The resolved key: 123
@Cacheable(key="#body_json('account.id')")
```

#### Pool

[](#pool)

You can [define](https://symfony.com/doc/current/cache.html) your own cache pool and use it instead of the default `cache.app`. Keep in mind that the cache pool must be defined as public.

#### TTL

[](#ttl)

Time to live of the cache item in seconds. If not defined will be used a pool default value.

#### Condition

[](#condition)

If we want more control over when the annotation is active, we can parameterize @Cacheable with a condition parameter that takes a Symfony expression and ensures that the results are cached based on evaluating that expression.

### @CacheEvict

[](#cacheevict)

`@CacheEvict(pool=, key=)`

Console command
---------------

[](#console-command)

- `php ./bin/console debug:response-cache`[![console-output.png](console-output.png)](console-output.png)

###  Health Score

20

—

LowBetter than 12% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity28

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/b12bdb9c0f7d0eaeac115fb72645c4d93e0f38f4aa2a84b8d8bcef1a09773ecd?d=identicon)[paveldanilin](/maintainers/paveldanilin)

---

Top Contributors

[![paveldanilin](https://avatars.githubusercontent.com/u/1683893?v=4)](https://github.com/paveldanilin "paveldanilin (58 commits)")

---

Tags

annotationcachecacheablecacheevictphpsymfonysymfony-bundle

### Embed Badge

![Health badge](/badges/paveldanilin-response-cache-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/paveldanilin-response-cache-bundle/health.svg)](https://phpackages.com/packages/paveldanilin-response-cache-bundle)
```

###  Alternatives

[iazaran/smart-cache

Smart Cache is a caching optimization package designed to enhance the way your Laravel application handles data caching. It intelligently manages large data sets by compressing, chunking, or applying other optimization strategies to keep your application performant and efficient.

21114.2k](/packages/iazaran-smart-cache)[phpfastcache/phpssdb

PHP SSDB Driver for phpFastCache

14736.9k1](/packages/phpfastcache-phpssdb)

PHPackages © 2026

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