create-cache-aside
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "create-cache-aside" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-c47a3758a03db735286f6b5d1da5a3c7db9b80c8f1574c30b7a90d74898370df. Verify the upstream source and version against https://github.com/dykyi-roman/awesome-claude-code before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
github.com
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Generate a Cache-Aside pattern implementation for PHP 8.4. Creates a cache executor with PSR-16 integration, supports stampede protection via distributed locks, tag-based invalidation, and key generation features, and includes unit tests.
Introduction source: third_party · dykyi-roman · 0.0.1 Reference
SkillPi interpretation
- Tasks
- Generates Cache-Aside pattern for PHP 8.4. Creates cache executor with PSR-16 integration, stampede protection via distributed locking, tag-based invalidation, and key generation. Includes unit tests.
- Audience
- | Scenario | Example | |----------|---------| | Read-heavy workloads | Product catalog, user profiles | | Expensive queries | Complex reports, aggregated data | | External API responses | Third-party API caching | | Computed values | Pricing calculations, search results |
- Testing
- Not tested
Browse files
Frontmatter
name: create-cache-aside
description: Generates Cache-Aside pattern for PHP 8.4. Creates cache executor with PSR-16 integration, stampede protection via distributed locking, tag-based invalidation, and key generation. Includes unit tests.Cache-Aside Generator
Creates Cache-Aside infrastructure with stampede protection and tag-based invalidation.
When to Use
| Scenario | Example |
|---|---|
| Read-heavy workloads | Product catalog, user profiles |
| Expensive queries | Complex reports, aggregated data |
| External API responses | Third-party API caching |
| Computed values | Pricing calculations, search results |
Component Characteristics
CacheAsideInterface
get(string $key, callable $loader, int $ttl): mixed— load from cache or computeinvalidate(string $key): void— remove specific cache entryinvalidateByTag(string $tag): void— remove all entries tagged with given tag
CacheKeyGenerator
- Builds deterministic cache keys from prefix and parameters
- Hashes long keys to prevent exceeding storage limits
- Supports tag-based key grouping
CacheAsideExecutor
- PSR-16 SimpleCache integration
- Configurable TTL per cache operation
- Stampede protection via distributed locking
- Prevents thundering herd on cache miss
CacheInvalidator
- Tag-based invalidation (invalidate all entries for a tag)
- Pattern-based clearing (wildcard key matching)
- Batch invalidation support
Generation Process
Step 1: Generate Domain Components
Path: src/Domain/Shared/Cache/
CacheAsideInterface.php— Cache-aside contractCacheKeyGeneratorInterface.php— Key generation contract
Step 2: Generate Infrastructure Components
Path: src/Infrastructure/Cache/
CacheKeyGenerator.php— Key builder with hashingCacheAsideExecutor.php— PSR-16 cache executor with lockingCacheInvalidator.php— Tag-based and pattern-based invalidationCacheLockInterface.php— Distributed lock contractRedisCacheLock.php— Redis-based lock implementation
Step 3: Generate Tests
CacheKeyGeneratorTest.php— Key generation and hashing testsCacheAsideExecutorTest.php— Cache hit/miss, stampede protection testsCacheInvalidatorTest.php— Tag and pattern invalidation tests
File Placement
| Component | Path |
|---|---|
| Domain Interfaces | src/Domain/Shared/Cache/ |
| Infrastructure | src/Infrastructure/Cache/ |
| Unit Tests | tests/Unit/Infrastructure/Cache/ |
Naming Conventions
| Component | Pattern | Example |
|---|---|---|
| Interface | CacheAsideInterface |
CacheAsideInterface |
| Key Generator | CacheKeyGenerator |
CacheKeyGenerator |
| Executor | CacheAsideExecutor |
CacheAsideExecutor |
| Invalidator | CacheInvalidator |
CacheInvalidator |
| Lock Interface | CacheLockInterface |
CacheLockInterface |
| Lock Impl | {Store}CacheLock |
RedisCacheLock |
| Test | {ClassName}Test |
CacheAsideExecutorTest |
Quick Template Reference
CacheAsideInterface
interface CacheAsideInterface
{
/**
* @template T
* @param callable(): T $loader
* @return T
*/
public function get(string $key, callable $loader, int $ttl = 3600): mixed;
public function invalidate(string $key): void;
public function invalidateByTag(string $tag): void;
}
CacheKeyGenerator
final readonly class CacheKeyGenerator
{
public function __construct(private string $prefix = 'app');
public function generate(string $context, string ...$parts): string;
public function generateHashed(string $context, string ...$parts): string;
}
CacheLockInterface
interface CacheLockInterface
{
public function acquire(string $key, int $ttl = 10): bool;
public function release(string $key): void;
}
Usage Example
$executor = new CacheAsideExecutor($cache, $lock, defaultTtl: 3600);
// Cache-aside: returns cached value or computes via loader
$product = $executor->get(
key: 'product:123',
loader: fn() => $repository->findById(123),
ttl: 1800
);
// Invalidate on update
$executor->invalidate('product:123');
// Tag-based invalidation
$invalidator->invalidateByTag('products');
Pattern Comparison
| Pattern | Description | Use Case |
|---|---|---|
| Cache-Aside | App manages cache (check → miss → load → store) | Read-heavy, tolerates stale data |
| Read-Through | Cache loads data on miss (transparent to app) | Simpler app code, cache manages loading |
| Write-Through | Write to cache and DB simultaneously | Strong consistency needed |
| Write-Behind | Write to cache, async write to DB | High write throughput, eventual consistency |
Anti-patterns to Avoid
| Anti-pattern | Problem | Solution |
|---|---|---|
| No TTL | Stale data served forever | Always set TTL, even long ones |
| Thundering herd | All requests compute on cache miss | Stampede protection with locking |
| Cache poisoning | Invalid data cached | Validate data before caching |
| Inconsistent invalidation | Update DB but forget cache | Use events/listeners for invalidation |
| Key collisions | Different data for same key | Use prefix + context + params |
| Over-caching | Memory waste, stale data | Cache only expensive/frequent operations |
References
For complete PHP templates and examples, see:
references/templates.md— CacheAsideInterface, CacheKeyGenerator, CacheAsideExecutor, CacheInvalidator, lock templatesreferences/examples.md— Repository integration, event-driven invalidation, and unit tests
Current listing version
0.0.1
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 提供完整的缓存旁路模式实现,适用于高频读取场景
- 集成 PSR-16 标准,支持分布式锁和标签失效机制
- 包含单元测试,确保代码质量
Highlights
- description 明确描述功能,覆盖多种使用场景
- 触发词精准完整,边界清晰
Areas to improve
-
Document is too long Reported severity: Minor
文档约 600 行,超出建议的 500 行限制
Recommendation: 考虑拆分文档或精简内容
Highlights
- 结构清晰,分步骤生成
- 包含接口定义、实现类、测试用例
- frontmatter 完整
Highlights
- 工具来源明确(PSR-16、Redis)
- 参数正确,覆盖异常处理(惊群保护)
- 不可逆操作有确认机制
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
These common operations were not identified in the main document. This does not mean no permissions or risks exist.
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.