PHPackages                             tourze/symfony-aop-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. tourze/symfony-aop-cache-bundle

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

tourze/symfony-aop-cache-bundle
===============================

基于AOP的Symfony缓存增强包，提供注解式缓存支持和Redis标签清理功能

0.2.0(6mo ago)090MITPHPCI passing

Since Apr 8Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/tourze/symfony-aop-cache-bundle)[ Packagist](https://packagist.org/packages/tourze/symfony-aop-cache-bundle)[ RSS](/packages/tourze-symfony-aop-cache-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (22)Versions (7)Used By (0)

AopCacheBundle
==============

[](#aopcachebundle)

[English](README.md) | [中文](README.zh-CN.md)

[![Latest Version](https://camo.githubusercontent.com/d581536646e13e2db57354c0ae97e6d11d7983ad724140ecbbf9cba83b2fe135/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f73796d666f6e792d616f702d63616368652d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/symfony-aop-cache-bundle)[![PHP Version](https://camo.githubusercontent.com/9882b0c17158979467af6007204bf8d35c0c724707f09f91ed2a5f1e6585c812/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f75727a652f73796d666f6e792d616f702d63616368652d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/symfony-aop-cache-bundle)[![License](https://camo.githubusercontent.com/63038b07b1aefc44e18742b54cf10d495703300fbcfaedd0e0fcd6a65bd8216e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f746f75727a652f73796d666f6e792d616f702d63616368652d62756e646c653f7374796c653d666c61742d737175617265)](LICENSE)[![Build Status](https://camo.githubusercontent.com/7bef191b6942843e5832593989c6c3b84d0c6ca8b02e73ea0ee248b9e05dd3c5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f746f75727a652f6d6f6e6f7265706f2f746573742e796d6c3f7374796c653d666c61742d737175617265)](https://github.com/tourze/monorepo/actions)[![Code Coverage](https://camo.githubusercontent.com/ac8c8ca24a23c6a1e2dd761d3344a076bc41eb5f40877e97238f4ee77d209037/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f746f75727a652f6d6f6e6f7265706f3f7374796c653d666c61742d737175617265)](https://codecov.io/gh/tourze/monorepo)[![Total Downloads](https://camo.githubusercontent.com/2f597426b5d3d7b3adf081ea48d4d09236ea798825f109440f0d9111071c0c7e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f75727a652f73796d666f6e792d616f702d63616368652d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/symfony-aop-cache-bundle)

AopCacheBundle is a Symfony bundle that provides advanced, annotation-driven caching capabilities using AOP (Aspect-Oriented Programming). It enables developers to add cache logic to methods declaratively, supporting cache tags, TTL, custom keys, and forced cache refresh.

Features
--------

[](#features)

- Annotation-based declarative cache (`#[Cacheble]`, `#[CachePut]`)
- Custom cache key with Twig syntax
- Cache tags for batch management and cleaning
- TTL (expiration) control
- Forced cache refresh support
- Extensible aspects and cache logic

Dependencies
------------

[](#dependencies)

This package requires the following dependencies:

- PHP &gt;= 8.1
- Symfony Framework Bundle &gt;= 6.4
- Symfony Cache Component &gt;= 6.4
- Redis PHP extension
- Twig template engine
- AOP Bundle for aspect-oriented programming support

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

[](#installation)

**Install via Composer:**

```
composer require tourze/symfony-aop-cache-bundle
```

**Enable the Bundle:**

```
// config/bundles.php
return [
    // ...
    Tourze\Symfony\AopCacheBundle\AopCacheBundle::class => ['all' => true],
    // ...
];
```

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

[](#configuration)

The bundle automatically integrates with Symfony's cache configuration. Ensure your cache is properly configured:

```
# config/packages/cache.yaml
framework:
    cache:
        app: cache.adapter.redis
        pools:
            cache.app:
                adapter: cache.adapter.redis
                default_lifetime: 3600
```

Quick Start
-----------

[](#quick-start)

### Basic Usage

[](#basic-usage)

1. Add `#[Cacheble]` annotation to your method:

```
use Tourze\Symfony\AopCacheBundle\Attribute\Cacheble;

class UserService
{
    #[Cacheble(ttl: 3600, tags: ["user"])]
    public function getUserProfile(int $userId): array
    {
        // business logic
    }
}
```

2. Use custom cache key and tags:

```
#[Cacheble(key: "profile_{{ userId }}", tags: ["profile", "user_{{ userId }}"])]
public function getUserProfile(int $userId): array
{
    // ...
}
```

3. Force cache refresh:

```
use Tourze\Symfony\AopCacheBundle\Attribute\CachePut;

#[CachePut(key: "profile_{{ userId }}")]
public function updateProfile(int $userId, array $data): array
{
    // ...
}
```

Cache Key Templates
-------------------

[](#cache-key-templates)

Cache key template supports:

- Access parameters: `{{ paramName }}`
- Access join point info: `{{ joinPoint.method }}`, `{{ joinPoint.class }}`
- Supports all Twig syntax

Advanced Usage
--------------

[](#advanced-usage)

Cache Management Commands
-------------------------

[](#cache-management-commands)

The bundle provides a command for batch cache cleaning by tags:

```
# Clear Redis cache by tags (runs daily at 5:10 AM by default)
php bin/console cache:redis-clear-tags
```

Extending Cache Logic
---------------------

[](#extending-cache-logic)

You can extend the bundle's functionality by:

1. **Custom Cache Aspects**: Extend `CachebleAspect` or `CachePutAspect`
2. **Custom Cache Traits**: Use `CacheTrait` for reusable cache logic
3. **Custom Attributes**: Implement `CacheAttributeInterface`

Best Practices
--------------

[](#best-practices)

- **Supported Return Types**: Cache simple types (strings, numbers, arrays) or serializable objects
- **Avoid Caching**: Resource types, callbacks, or complex entity objects
- **Performance**: Use cache tags for efficient batch invalidation
- **Custom Logic**: Extend `CacheTrait`, `CachebleAspect`, or `CachePutAspect`for custom behavior

Contributing
------------

[](#contributing)

1. Fork the repository
2. Create a feature branch
3. Ensure all tests pass: `phpunit`
4. Follow PSR-12 coding standards
5. Submit a pull request

Please see [CONTRIBUTING.md](CONTRIBUTING.md) for detailed contribution guidelines.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

Changelog
---------

[](#changelog)

See [CHANGELOG.md](CHANGELOG.md) for version history and changes.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance72

Regular maintenance activity

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity31

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.

###  Release Activity

Cadence

Every ~43 days

Recently: every ~50 days

Total

6

Last Release

180d ago

### Community

Maintainers

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

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-symfony-aop-cache-bundle/health.svg)

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

###  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.6M650](/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)[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)[simplesamlphp/simplesamlphp

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

1.1k12.4M193](/packages/simplesamlphp-simplesamlphp)

PHPackages © 2026

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