PHPackages                             php-solution/app-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. php-solution/app-cache-bundle

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

php-solution/app-cache-bundle
=============================

Symfony bundle for using Redis as main cache on app.

v4.0.1(8y ago)25.6kMITPHPPHP &gt;=7.1

Since Apr 4Pushed 8y ago2 watchersCompare

[ Source](https://github.com/php-solution/sf-app-cache-bundle)[ Packagist](https://packagist.org/packages/php-solution/app-cache-bundle)[ RSS](/packages/php-solution-app-cache-bundle/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (7)Versions (6)Used By (0)

AppCacheBundle
==============

[](#appcachebundle)

This bundle allows developer to use Redis as main cache provider on Symfony application.

Better Performance:

- Bundle composer.json includes `ext-redis` on require part, because [phpredis lib](https://github.com/phpredis/phpredis) allow you better performance using Redis on app.
- For serialization please install and enable php extension [igbinary](https://pecl.php.net/package/igbinary).

Redis Clients
-------------

[](#redis-clients)

You can specify Redis Client as service on Symfony DI.

As default new DI Reference will created via factory `\PhpSolution\Utils\ClientFactory::createRedisClient()` and set correct serializer option for \\Redis.

Example of configuration:

```
app_cache:
    redis_clients:
        general:
            public: false
            id: 'app_cache.redis_clients.general'
            class: 'Redis'
            dsn: 'redis://localhost:6379/db_name'
            options: ~

```

On app

```
/* @var $client \Redis */
$client = $this->container->get('app_cache.redis_clients.general');
$client->set('key', 'value');
$string = $client->get('key'); // $string === 'value'

```

Integration with SymfonyFrameworkBundle
---------------------------------------

[](#integration-with-symfonyframeworkbundle)

### Cache Spool

[](#cache-spool)

You can use Redis client service as [SF cache pool provider](http://symfony.com/doc/current/components/cache/cache_pools.html)

Example of app\_cache bundle configuration:

```
app_cache:
    redis_clients:
        general:
            id: 'app_cache.redis_clients.general'
            dsn: 'redis://localhost:6379/data_base_name'

```

Example of FrameworkBundle configuration:

```
framework:
    cache:
        pools:
            cache_pools.redis.general:
                public: false
                default_lifetime: 0
                adapter: 'cache.adapter.redis'
                provider: 'app_cache.redis_clients.general' # Redis client service id

```

### Cache providers

[](#cache-providers)

SymfonyFrameworkBundle allows you to cache:

- validation mapper cache (on prod use file\_cache)
- serializer mapper cache (on prod use file\_cache)
- annotations (you can use php\_array, )
- templating (use only for php template engine, [see more](http://symfony.com/doc/current/reference/configuration/framework.html#cache))

##### Use Redis for validation mapper cache:

[](#use-redis-for-validation-mapper-cache)

```
app_cache:
    redis_clients:
        general:
            id: 'app_cache.redis_clients.general'
            dsn: 'redis://localhost:6379/db_name'
    framework:
        validator:
            enabled: true
            client_id: 'app_cache.redis_clients.general'
            namespace: 'sf_validator'

framework:
    validation:
        enable_annotations: true
        cache: 'app_cache.framework.validator_mapping_cache'

```

##### Use Redis for serializer mapper cache:

[](#use-redis-for-serializer-mapper-cache)

```
app_cache:
    redis_clients:
        general:
            id: 'app_cache.redis_clients.general'
            dsn: 'redis://localhost:6379/db_name'
    framework:
        serializer:
            enabled: true
            client_id: 'app_cache.redis_clients.general'
            namespace: 'sf_serializer'

framework:
    validation:
        enable_annotations: true
        cache: 'app_cache.framework.validator_mapping_cache'

```

Swiftmailer Spool
-----------------

[](#swiftmailer-spool)

You can use Redis as storage for spool swiftmailer messages.

AppCacheBundle configuration:

```
app_cache:
    redis_clients:
        general:
            id: 'app_cache.redis_clients.general'
            dsn: 'redis://localhost:6379/data_base_name'
    swiftmailer:
        enabled: true
        client_id: 'app_cache.redis_clients.general'

```

SwiftmailerBundle configuration:

```
swiftmailer:
    spool:
        type: 'service'
        id: 'app_cache.cacheable.swiftmailer_spool'

```

You can customize spool service:

```
app_cache:
    swiftmailer:
        enabled: true
        client_id: 'app_cache.redis_clients.general'
        cache_key: 'swiftmailer_spool'

```

Sessions Handler
----------------

[](#sessions-handler)

You can use Redis as storage for session. Bundle includes SessionHandle, on DI `'app_cache.cacheable.session_handler'` which injects \\Redis client and stores sessions on \\Redis.

Example of AppCacheBundle configuration:

```
app_cache:
    redis_clients:
        general:
            id: 'app_cache.redis_clients.general'
            dsn: 'redis://localhost:6379/db_name'
    session:
        enabled: true
        client_id: 'app_cache.redis_clients.general'

```

Example of FrameworkBundle configuration:

```
    framework:
        session:
            handler_id: 'app_cache.cacheable.session_handler'

```

You can customize Session Handler:

```
app_cache:
    session:
        enabled: true
        client_id: 'app_cache.redis_clients.general'
        ttl: 86400
        cache_key: 'sfs_'

```

Doctrine Cache Providers
------------------------

[](#doctrine-cache-providers)

You can specify services as Doctrine cache providers. Example of configurations:

```
app_cache:
    redis_clients:
        general:
            id: 'app_cache.redis_clients.general'
            dsn: 'redis://localhost:6379/db_name'
    doctrine:
        providers:
            general:
                id: 'app_cache.doctrine_providers.redis'
                class: 'Doctrine\Common\Cache\RedisCache'
                client_id: 'app_cache.redis_clients.general'
                namespace: 'doctrine'

```

### Correct Doctrine Cache Driver configuration

[](#correct-doctrine-cache-driver-configuration)

Correct configuration for doctrine:

```
app_cache:
    redis_clients:
        general:
            id: 'app_cache.redis_clients.general'
            dsn: 'redis://localhost:6379/db_name'
    doctrine:
        providers:
            general:
                id: 'app_cache.doctrine_providers.redis'
                client_id: 'app_cache.redis_clients.general'
                namespace: 'doctrine'

parameters:
    doctrine_cache.metadata_cache_driver: {type: 'service', id: 'app_cache.doctrine_providers.redis'}
    doctrine_cache.query_cache_driver: {type: 'service', id: 'app_cache.doctrine_providers.redis'}
    doctrine_cache.result_cache_driver: {type: 'service', id: 'app_cache.doctrine_providers.redis'}
    doctrine_cache.slc_driver: {type: 'service', id: 'app_cache.doctrine_providers.redis'}

doctrine:
    orm:
        entity_managers:
            default:
                metadata_cache_driver: '%doctrine_cache.metadata_cache_driver%'
                query_cache_driver: '%doctrine_cache.query_cache_driver%'
                result_cache_driver: '%doctrine_cache.result_cache_driver%'
                second_level_cache:
                    region_cache_driver: '%doctrine_cache.slc_driver%'
                    regions:
                        concurrent_entity_region:
                            type: 'filelock'
                            cache_driver: '%doctrine_cache.slc_driver%'
                        entity_region:
                             lifetime: 0
                             cache_driver: '%doctrine_cache.slc_driver%'

```

### Doctrine Cache Driver configuration (ONLY FOR BASIC USAGE!!!)

[](#doctrine-cache-driver-configuration-only-for-basic-usage)

This Bundle allows you to specify cache provider for:

- metadata\_cache
- result\_cache
- query\_cache
- second\_level\_cache

This functionality works like on [SncRedisBundle](https://github.com/snc/SncRedisBundle/blob/master/Resources/doc/index.md#doctrine-caching) and assign Doctrine cache provider automatically, but use only alias for cache provider, not creates separate provider.

Example of configuration:

```
app_cache:
    redis_clients:
        general:
            id: 'app_cache.redis_clients.general'
            dsn: 'redis://localhost:6379/db_name'
    doctrine:
        providers:
            general:
                id: 'app_cache.doctrine_providers.redis'
                client_id: 'app_cache.redis_clients.general'
        cache:
            metadata_cache:
                provider_id: 'app_cache.doctrine_providers.redis'
                entity_managers: ['default']

```

Bundle Extension create new alias for services (patter name: `doctrine.orm.%s_%s`) using as cache\_driver.

For example `doctrine.orm.default_metadata_cache` - service name for `metadata_cache` for `default` entity manager.

Use this feature only for basic configuration of Doctrine, because:

- you cannot rewrite for env's cache driver params
- you cannot specify `second_level_cache` regions parameters
- this bundle must be specified on AppKernel after DoctrineBundle

Twig cache
----------

[](#twig-cache)

Twig use Filesystem cache as provider for cache templates. You must use Filesystem cache (not Redis and other provider) and for best performance please configure PHP opcache.

Additional info about Twig cache on [link](https://github.com/twigphp/Twig/commit/87e27b6a26fd477a407bf98b4c7af04455437f6a)

Full Default Configuration
--------------------------

[](#full-default-configuration)

```
app_cache:
    redis_clients:
        general:
            id: 'app_cache.redis_clients.general'
            class: 'Redis'
            dsn: 'redis://localhost:6379/db_name'
            options: ~
    framework:
        validator:
            enabled: true
            client_id: 'app_cache.redis_clients.general'
            namespace: 'sf_validator'
        serializer:
            enabled: true
            client_id: 'app_cache.redis_clients.general'
            namespace: 'sf_serializer'
    swiftmailer:
        enabled: true
        client_id: 'app_cache.redis_clients.general'
        cache_key: 'swiftmailer_spool'
    session:
        enabled: true
        client_id: 'app_cache.redis_clients.general'
        ttl: 86400
        cache_key: 'sfs_'
    doctrine:
        providers:
            general:
                id: 'app_cache.doctrine_providers.redis'
                class: 'Doctrine\Common\Cache\RedisCache'
                client_id: 'app_cache.redis_clients.general'
                namespace: 'doctrine'
        cache:
            metadata_cache:
                provider_id: 'app_cache.doctrine_providers.redis'
                entity_managers: ['default']
                document_managers: ['default']
            result_cache:
                provider_id: 'app_cache.doctrine_providers.redis'
                entity_managers: ['default']
                document_managers: ['default']
            query_cache:
                provider_id: 'app_cache.doctrine_providers.redis'
                entity_managers: ['default']
                document_managers: ['default']
            second_level_cache:
                provider_id: 'app_cache.doctrine_providers.redis'
                entity_managers: ['default']
                document_managers: ['default']

```

Working with not prod environments
----------------------------------

[](#working-with-not-prod-environments)

### Test environment

[](#test-environment)

The test environment must be the same as production environment. Therefore, for test environment, it is recommended to clean the cache before starting the test cases.

Cleaning cache with listeners. **phpunit.xml** example:

```

    ...

        ...

                doctrine:cache:clear-metadata

                doctrine:cache:clear-query

                doctrine:cache:clear-result

        ...

```

### Dev environment

[](#dev-environment)

For dev environment, it is not recommended to use caching

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity62

Established project with proven stability

 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.

###  Release Activity

Cadence

Every ~72 days

Total

5

Last Release

3041d ago

Major Versions

v0.1.1 → v4.0.02017-12-13

### Community

Maintainers

![](https://www.gravatar.com/avatar/49381ba2a061a148b9a6f7b5e80663f17d44f15047bbc5f1f38d13429de60487?d=identicon)[olesav](/maintainers/olesav)

---

Top Contributors

[![kalinick](https://avatars.githubusercontent.com/u/1422388?v=4)](https://github.com/kalinick "kalinick (2 commits)")

### Embed Badge

![Health badge](/badges/php-solution-app-cache-bundle/health.svg)

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

###  Alternatives

[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[sulu/sulu

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

1.3k1.3M152](/packages/sulu-sulu)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[scheb/2fa

Two-factor authentication for Symfony applications (please use scheb/2fa-bundle to install)

578630.7k1](/packages/scheb-2fa)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

7310.3k29](/packages/open-dxp-opendxp)

PHPackages © 2026

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