This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Ray.PsrCacheModule is a dependency injection module for Ray.Di that provides PSR-6 (Cache) and PSR-16 (Simple Cache) interface bindings. It supports multiple cache backends (Redis, Memcached, APCu, Filesystem, Array) and distinguishes between "Local" (non-shared) and "Shared" (multi-server) cache types.
The project uses Ray.Di's module system to bind cache implementations:
- Psr6*Module classes (e.g.,
Psr6RedisModule,Psr6ApcuModule) configure dependency injection bindings - Each module binds
CacheItemPoolInterfacewith either#[Local]or#[Shared]annotations - Modules can be chained using the optional
$moduleconstructor parameter
- Custom Adapters:
RedisAdapter,MemcachedAdapter,ApcuAdapter,FilesystemAdapterextend Symfony Cache adapters - Serialization: Custom adapters use
SerializableTraitto make Redis/Memcached connections serializable (required for DI container serialization) - Provider Pattern: Complex cache setup uses providers (e.g.,
ImmutableCacheProvider,LocalCacheProvider,RedisProvider)
#[Local]- For caches that don't need cross-server sharing#[Shared]- For caches shared across multiple servers#[CacheDir],#[CacheNamespace],#[RedisConfig],#[MemcacheConfig]- Configuration injection
src/- Main source codesrc-deprecated/- Deprecated code (e.g., typoMemcachdAdapter.php)src-files/- Polyfill files (e.g.,apcu.phpfor testing)tests/- PHPUnit tests (all PHP versions)tests-php8/- PHP 8+ specific teststests-pecl-ext/- Tests requiring PECL extensions (Redis, Memcached)
composer test # Run PHPUnit tests only
composer tests # Run coding standards, static analysis, and tests (use before PR)
composer coverage # Generate coverage report with Xdebug
composer pcov # Generate coverage report with PCOV (faster)composer cs # Check coding standards (PSR-12)
composer cs-fix # Fix coding standard violations (REQUIRED before commit)
composer sa # Run static analysis (PHPStan + Psalm)
composer clean # Clear PHPStan and Psalm cachescomposer setup # Initial project setup
composer build # Full build: clean, cs, sa, pcov, metrics
composer metrics # Generate code metrics report./vendor/bin/phpunit tests/Psr6CacheTest.php
./vendor/bin/phpunit --filter testMethodName- Before making changes: Understand the module you're modifying (e.g.,
Psr6RedisModulebinds Redis for Shared, APCu for Local) - After code changes: Run
composer cs-fixto fix code style - Before committing: Run
composer teststo ensure quality gates pass - For coverage: Use
composer pcov(faster than Xdebug)
Cache adapters (Redis, Memcached) MUST be serializable because Ray.Di can serialize the entire object graph. Use SerializableTrait for custom adapters that wrap non-serializable resources.
- Module binds interfaces with annotations (e.g.,
CacheItemPoolInterfacewith#[Shared]) - Optional configuration modules (
CacheDirModule,CacheNamespaceModule) inject configuration values - Providers instantiate actual cache instances with injected configuration
- Ray.Di resolves dependencies based on annotations at injection points
Tests in tests-pecl-ext/ require Redis/Memcached extensions installed. These tests are conditionally run based on PHP version (see phpunit.xml.dist).
- Follow PSR-12 coding standard (enforced by
composer cs) - Declare strict types:
declare(strict_types=1); - Use readonly properties where appropriate (PHP 8.1+)
- Maintain PHPStan level 9 and Psalm compliance