create-psr16-simple-cache
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-psr16-simple-cache" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-750e641ae9f31fba9399a21705d42413859b18be0421371e09a2eded9a042438. 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 PSR-16 simple cache implementation for PHP 8.4. Create a CacheInterface implementation providing get, set, and delete operations with TTL handling, and include unit tests.
Introduction source: third_party · dykyi-roman · 0.0.1 Reference
SkillPi interpretation
- Tasks
- Generates PSR-16 Simple Cache implementation for PHP 8.4. Creates CacheInterface with get/set/delete operations and TTL handling. Includes unit tests.
- Audience
- Simple key-value caching Performance-critical code paths Minimal caching abstraction Quick cache integration
- Testing
- Not tested
Browse files
Frontmatter
name: create-psr16-simple-cache
description: Generates PSR-16 Simple Cache implementation for PHP 8.4. Creates CacheInterface with get/set/delete operations and TTL handling. Includes unit tests.PSR-16 Simple Cache Generator
Overview
Generates PSR-16 compliant simple cache implementations for basic caching needs.
When to Use
- Simple key-value caching
- Performance-critical code paths
- Minimal caching abstraction
- Quick cache integration
Template: Array Cache
<?php
declare(strict_types=1);
namespace App\Infrastructure\Cache;
use DateInterval;
use DateTimeImmutable;
use Psr\SimpleCache\CacheInterface;
final class ArrayCache implements CacheInterface
{
/** @var array<string, array{value: mixed, expiration: ?int}> */
private array $cache = [];
public function get(string $key, mixed $default = null): mixed
{
$this->validateKey($key);
if (!isset($this->cache[$key])) {
return $default;
}
$item = $this->cache[$key];
if ($item['expiration'] !== null && $item['expiration'] < time()) {
unset($this->cache[$key]);
return $default;
}
return $item['value'];
}
public function set(string $key, mixed $value, null|int|DateInterval $ttl = null): bool
{
$this->validateKey($key);
$expiration = $this->calculateExpiration($ttl);
$this->cache[$key] = [
'value' => $value,
'expiration' => $expiration,
];
return true;
}
public function delete(string $key): bool
{
$this->validateKey($key);
unset($this->cache[$key]);
return true;
}
public function clear(): bool
{
$this->cache = [];
return true;
}
public function getMultiple(iterable $keys, mixed $default = null): iterable
{
$result = [];
foreach ($keys as $key) {
$result[$key] = $this->get($key, $default);
}
return $result;
}
public function setMultiple(iterable $values, null|int|DateInterval $ttl = null): bool
{
foreach ($values as $key => $value) {
$this->set($key, $value, $ttl);
}
return true;
}
public function deleteMultiple(iterable $keys): bool
{
foreach ($keys as $key) {
$this->delete($key);
}
return true;
}
public function has(string $key): bool
{
return $this->get($key, $this) !== $this;
}
private function calculateExpiration(null|int|DateInterval $ttl): ?int
{
if ($ttl === null) {
return null;
}
if ($ttl instanceof DateInterval) {
return (new DateTimeImmutable())->add($ttl)->getTimestamp();
}
return time() + $ttl;
}
private function validateKey(string $key): void
{
if ($key === '' || preg_match('/[{}()\/\\\\@:]/', $key)) {
throw new InvalidArgumentException("Invalid cache key: {$key}");
}
}
}
Template: Redis Cache
<?php
declare(strict_types=1);
namespace App\Infrastructure\Cache;
use DateInterval;
use DateTimeImmutable;
use Psr\SimpleCache\CacheInterface;
use Redis;
final readonly class RedisCache implements CacheInterface
{
public function __construct(
private Redis $redis,
private string $prefix = 'cache:',
) {
}
public function get(string $key, mixed $default = null): mixed
{
$value = $this->redis->get($this->prefix . $key);
if ($value === false) {
return $default;
}
return unserialize($value);
}
public function set(string $key, mixed $value, null|int|DateInterval $ttl = null): bool
{
$serialized = serialize($value);
$fullKey = $this->prefix . $key;
if ($ttl === null) {
return $this->redis->set($fullKey, $serialized);
}
$seconds = $ttl instanceof DateInterval
? (new DateTimeImmutable())->add($ttl)->getTimestamp() - time()
: $ttl;
return $this->redis->setex($fullKey, $seconds, $serialized);
}
public function delete(string $key): bool
{
return $this->redis->del($this->prefix . $key) > 0;
}
public function clear(): bool
{
$keys = $this->redis->keys($this->prefix . '*');
if (!empty($keys)) {
$this->redis->del($keys);
}
return true;
}
public function getMultiple(iterable $keys, mixed $default = null): iterable
{
$result = [];
foreach ($keys as $key) {
$result[$key] = $this->get($key, $default);
}
return $result;
}
public function setMultiple(iterable $values, null|int|DateInterval $ttl = null): bool
{
foreach ($values as $key => $value) {
$this->set($key, $value, $ttl);
}
return true;
}
public function deleteMultiple(iterable $keys): bool
{
foreach ($keys as $key) {
$this->delete($key);
}
return true;
}
public function has(string $key): bool
{
return $this->redis->exists($this->prefix . $key) > 0;
}
}
Template: Exceptions
<?php
declare(strict_types=1);
namespace App\Infrastructure\Cache;
use Psr\SimpleCache\CacheException as PsrCacheException;
use Psr\SimpleCache\InvalidArgumentException as PsrInvalidArgumentException;
final class CacheException extends \RuntimeException implements PsrCacheException
{
}
final class InvalidArgumentException extends \InvalidArgumentException implements PsrInvalidArgumentException
{
}
Usage Example
<?php
use App\Infrastructure\Cache\RedisCache;
$cache = new RedisCache($redis);
// Simple operations
$cache->set('user:123', $userData, 3600);
$user = $cache->get('user:123');
// Check existence
if ($cache->has('user:123')) {
$cache->delete('user:123');
}
// Multiple operations
$cache->setMultiple([
'config:app' => $appConfig,
'config:db' => $dbConfig,
], 86400);
$configs = $cache->getMultiple(['config:app', 'config:db']);
Requirements
{
"require": {
"psr/simple-cache": "^3.0"
}
}Current listing version
0.0.1
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 为PHP开发者提供PSR-16标准缓存实现,解决实际开发中的缓存需求
- 包含Array和Redis两种常用缓存实现,覆盖不同使用场景
- 提供完整的TTL处理和异常处理机制
Highlights
- 触发词精准覆盖PHP缓存开发场景
- 支持多种缓存操作变体(get/set/delete/批量操作)
- 明确区分不同缓存实现的使用场景
Highlights
- Phase/步骤清晰,包含完整的代码示例
- 提供When to Use章节说明适用场景
- frontmatter完整,文档结构规范
Highlights
- 代码实现符合PSR-16标准,参数处理正确
- 包含完整的异常处理机制
- 提供使用示例和依赖要求
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.