acc-create-psr16-simple-cache

Generates PSR-16 Simple Cache implementation for PHP 8.5. Creates CacheInterface with get/set/delete operations and TTL handling. Includes unit tests.

16 stars

Best use case

acc-create-psr16-simple-cache is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Generates PSR-16 Simple Cache implementation for PHP 8.5. Creates CacheInterface with get/set/delete operations and TTL handling. Includes unit tests.

Teams using acc-create-psr16-simple-cache should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/acc-create-psr16-simple-cache/SKILL.md --create-dirs "https://raw.githubusercontent.com/diegosouzapw/awesome-omni-skill/main/skills/development/acc-create-psr16-simple-cache/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/acc-create-psr16-simple-cache/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How acc-create-psr16-simple-cache Compares

Feature / Agentacc-create-psr16-simple-cacheStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Generates PSR-16 Simple Cache implementation for PHP 8.5. Creates CacheInterface with get/set/delete operations and TTL handling. Includes unit tests.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# 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
<?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
<?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
<?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
<?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

```json
{
    "require": {
        "psr/simple-cache": "^3.0"
    }
}
```

Related Skills

agent-ops-create-python-project

16
from diegosouzapw/awesome-omni-skill

Create a plan and issues for implementation of a production-ready Python project with proper structure, tooling, and best practices.

acc-create-use-case

16
from diegosouzapw/awesome-omni-skill

Generates Application Use Cases for PHP 8.5. Creates orchestration services that coordinate domain objects, handle transactions, and dispatch events. Includes unit tests.

acc-create-state

16
from diegosouzapw/awesome-omni-skill

Generates State pattern for PHP 8.5. Creates state machines with context, state interface, and concrete states for behavior changes. Includes unit tests.

acc-create-saga-pattern

16
from diegosouzapw/awesome-omni-skill

Generates Saga pattern components for PHP 8.5. Creates Saga interfaces, steps, orchestrator, state management, and compensation logic with unit tests.

acc-create-retry-pattern

16
from diegosouzapw/awesome-omni-skill

Generates Retry pattern for PHP 8.5. Creates resilience component with exponential backoff, jitter, and configurable retry strategies. Includes unit tests.

acc-create-responder

16
from diegosouzapw/awesome-omni-skill

Generates ADR Responder classes for PHP 8.5. Creates HTTP response builders with PSR-7/PSR-17 support. Includes unit tests.

acc-create-repository

16
from diegosouzapw/awesome-omni-skill

Generates DDD Repository interfaces and implementation stubs for PHP 8.5. Creates domain interfaces in Domain layer, implementation in Infrastructure.

acc-create-rate-limiter

16
from diegosouzapw/awesome-omni-skill

Generates Rate Limiter pattern for PHP 8.5. Creates request throttling with token bucket, sliding window, and fixed window algorithms. Includes unit tests.

acc-create-psr6-cache

16
from diegosouzapw/awesome-omni-skill

Generates PSR-6 Cache implementation for PHP 8.5. Creates CacheItemPoolInterface and CacheItemInterface implementations with TTL handling and deferred saves. Includes unit tests.

acc-create-psr3-logger

16
from diegosouzapw/awesome-omni-skill

Generates PSR-3 Logger implementation for PHP 8.5. Creates LoggerInterface implementations with log levels, context interpolation, and LoggerAwareTrait usage. Includes unit tests.

acc-create-psr20-clock

16
from diegosouzapw/awesome-omni-skill

Generates PSR-20 Clock implementation for PHP 8.5. Creates ClockInterface implementations including SystemClock, FrozenClock, and OffsetClock for time abstraction and testing. Includes unit tests.

acc-create-psr17-http-factory

16
from diegosouzapw/awesome-omni-skill

Generates PSR-17 HTTP Factories implementation for PHP 8.5. Creates RequestFactoryInterface, ResponseFactoryInterface, StreamFactoryInterface, UriFactoryInterface, ServerRequestFactoryInterface, UploadedFileFactoryInterface. Includes unit tests.