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 1mo 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

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity27

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

[predis/predis

A flexible and feature-complete Redis/Valkey client for PHP.

7.8k305.7M2.4k](/packages/predis-predis)[snc/redis-bundle

A Redis bundle for Symfony

1.0k39.4M67](/packages/snc-redis-bundle)[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[wp-media/wp-rocket

Performance optimization plugin for WordPress

7431.3M3](/packages/wp-media-wp-rocket)[illuminate/cache

The Illuminate Cache package.

12835.6M1.4k](/packages/illuminate-cache)[colinmollenhour/php-redis-session-abstract

A Redis-based session handler with optimistic locking

6325.6M14](/packages/colinmollenhour-php-redis-session-abstract)

PHPackages © 2026

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