PHPackages                             phillarmonic/staccache-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. phillarmonic/staccache-bundle

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

phillarmonic/staccache-bundle
=============================

A Symfony bundle for entity caching with locking support

1.0.0(1y ago)050MITPHPPHP &gt;=8.2

Since Mar 20Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Phillarmonic/staccache-bundle)[ Packagist](https://packagist.org/packages/phillarmonic/staccache-bundle)[ RSS](/packages/phillarmonic-staccache-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (12)Versions (2)Used By (0)

Staccache Bundle Documentation
==============================

[](#staccache-bundle-documentation)

**A Symfony bundle for efficient Doctrine entity caching with locking support**

Overview
--------

[](#overview)

The Staccache Bundle provides an easy way to implement entity caching in Symfony applications using Redis. It improves application performance by reducing database queries for frequently accessed entities. Key features include:

- Entity-level caching with automatic cache invalidation
- Collection and query result caching
- Distributed locking to prevent race conditions
- Integration with Symfony's form system for automatic cache updates
- Support for controller argument resolution with cached entities
- Compatible with multiple Redis client libraries (phpredis, predis, SNC Redis Bundle)

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

[](#installation)

### 1. Install the bundle with Composer

[](#1-install-the-bundle-with-composer)

```
composer require phillarmonic/staccache-bundle
```

### 2. Register the bundle in your application

[](#2-register-the-bundle-in-your-application)

For Symfony Flex applications, the bundle will be automatically registered. For manual registration, add it to your `config/bundles.php`:

```
return [
    // Other bundles...
    Phillarmonic\StaccacheBundle\StaccacheBundle::class => ['all' => true],
];
```

### 3. Configure Redis connection

[](#3-configure-redis-connection)

Create a configuration file at `config/packages/staccache.yaml`:

```
staccache:
    default_ttl: 3600  # Default TTL for cached entities in seconds (1 hour)
    lock_ttl: 30       # Default TTL for entity locks in seconds
    cache_prefix: staccache  # Prefix for cache keys
    auto_cache_on_load: true # Automatically cache entities when loaded

    # Redis connection configuration
    redis:
        driver: auto   # auto, phpredis, or predis
        host: localhost
        port: 6379
        # username: ~  # For Redis 6.0+ with ACL support
        # password: ~
        db: 0
        options:
            timeout: 5.0
            read_timeout: 5.0
            persistent: false
```

Basic Usage
-----------

[](#basic-usage)

### Marking Entities as Cacheable

[](#marking-entities-as-cacheable)

Add the `#[Staccacheable]` attribute to entity classes you want to cache:

```
