tourze / symfony-aop-cache-bundle
AOP缓存支持
Installs: 20
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^8.1
- ext-redis: *
- psr/cache: ^2.0 || ^3.0
- symfony/cache: ^6.4
- symfony/cache-contracts: ^3
- symfony/config: ^6.4
- symfony/console: ^6.4
- symfony/dependency-injection: ^6.4
- symfony/framework-bundle: ^6.4
- symfony/http-kernel: ^6.4
- symfony/var-exporter: ^6.4
- symfony/yaml: ^6.4 || ^7.1
- tourze/backtrace-helper: ~0.0.5
- tourze/doctrine-helper: 0.0.*
- tourze/symfony-aop-bundle: ~0.0.4
- tourze/symfony-cache-hotkey-bundle: 0.0.*
- tourze/symfony-cron-job-bundle: 0.1.*
- twig/twig: ^3.13|^4.0
Requires (Dev)
- maglnet/composer-require-checker: ^4
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2025-05-08 10:50:25 UTC
README
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
- 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
Installation
- Requires PHP >= 8.1
- Requires Symfony >= 6.4
- Requires Redis extension
composer require tourze/symfony-aop-cache-bundle
Quick Start
- 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 } }
- Use custom cache key and tags:
#[Cacheble(key: "profile_{{ userId }}", tags: ["profile", "user_{{ userId }}"])] public function getUserProfile(int $userId): array { // ... }
- Force cache refresh:
use Tourze\Symfony\AopCacheBundle\Attribute\CachePut; #[CachePut(key: "profile_{{ userId }}")] public function updateProfile(int $userId, array $data): array { // ... }
- Cache key template:
- Access parameters:
{{ paramName }}
- Access join point info:
{{ joinPoint.method }}
,{{ joinPoint.class }}
- Supports all Twig syntax
- Access parameters:
Documentation
- Support batch cache cleaning by tag (
cache:redis-clear-tags
command) - Do not cache resource types, callbacks, or entity objects; cache simple types or arrays
- Custom aspects and cache logic supported (extend
CacheTrait
,CachebleAspect
,CachePutAspect
)
Contributing
- Ensure code passes tests before submitting issues or PRs
- Follow PSR-12 coding style
- Read core class docs and comments first
License
- MIT License
- (c) tourze
Changelog
See [CHANGELOG.md]