本文へ移動
cccskills
無料GitHub で公開

acc-create-object-pool

Generates Object Pool pattern for PHP 8.5. Creates reusable object containers for expensive resources like connections. Includes unit tests.

インストール方法を見る

含まれるファイル(1)

  • SKILL.md4.7 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

Object Pool Pattern Generator

Creates Object Pool pattern infrastructure for managing reusable expensive objects.

When to Use

ScenarioExample
Expensive creationDatabase connections
Limited resourcesHTTP client handles
Connection reuseSocket connections
Memory managementLarge object caching

Component Characteristics

PoolInterface

  • Acquire/release semantics
  • Pool lifecycle management
  • Capacity configuration

Pool Implementation

  • Manages available objects
  • Creates on demand
  • Recycles returned objects

Poolable Objects

  • Resettable state
  • Validate before reuse
  • Track usage metrics

Generation Process

Step 1: Generate Core Pool Components

Path: src/Infrastructure/Pool/

  1. PoolInterface.php — Generic pool contract with acquire/release
  2. PoolConfig.php — Configuration value object (min/max size, timeouts)
  3. PoolableInterface.php — Contract for poolable objects (reset, isValid, close)
  4. ObjectPool.php — Generic pool implementation
  5. PooledObject.php — Wrapper tracking usage metrics
  6. PoolExhaustedException.php — Exception for exhausted pool
  7. InvalidPoolObjectException.php — Exception for invalid objects

Step 2: Generate Specialized Pool (if needed)

Path: src/Infrastructure/{Domain}/

  1. {Type}Pool.php — Specialized pool (ConnectionPool, HttpClientPool)
  2. Poolable{Type}.php — Poolable implementation for specific resource

Step 3: Generate Tests

Path: tests/Unit/Infrastructure/Pool/

  1. ObjectPoolTest.php — Core pool functionality tests
  2. {Type}PoolTest.php — Specialized pool tests

File Placement

ComponentPath
Pool Interfacesrc/Infrastructure/Pool/
Pool Implementationsrc/Infrastructure/Pool/
Specialized Poolssrc/Infrastructure/{Domain}/
Unit Teststests/Unit/Infrastructure/Pool/

Naming Conventions

ComponentPatternExample
InterfacePoolInterfacePoolInterface
ImplementationObjectPoolObjectPool
Poolable InterfacePoolableInterfacePoolableInterface
ConfigPoolConfigPoolConfig
WrapperPooledObjectPooledObject
Specialized Pool{Type}PoolConnectionPool
Test{ClassName}TestObjectPoolTest

Quick Template Reference

PoolInterface

/**
 * @template T
 */
interface PoolInterface
{
    /** @return T */
    public function acquire(): mixed;
    /** @param T $object */
    public function release(mixed $object): void;
    public function getAvailableCount(): int;
    public function getActiveCount(): int;
    public function getMaxSize(): int;
    public function clear(): void;
}

PoolableInterface

interface PoolableInterface
{
    public function reset(): void;
    public function isValid(): bool;
    public function close(): void;
}

PoolConfig

final readonly class PoolConfig
{
    public function __construct(
        public int $minSize = 0,
        public int $maxSize = 10,
        public int $maxWaitTimeMs = 5000,
        public int $idleTimeoutSeconds = 300,
        public bool $validateOnAcquire = true,
        public bool $validateOnRelease = false
    );

    public static function default(): self;
    public static function forDatabase(): self;
    public static function forHttpClients(): self;
}

Usage Example

// Create pool
$pool = new ObjectPool(
    name: 'database',
    factory: fn() => $connectionFactory->create(),
    config: PoolConfig::forDatabase(),
    logger: $logger
);

// Acquire and release
$connection = $pool->acquire();
try {
    $result = $connection->query('SELECT ...');
} finally {
    $pool->release($connection);
}

// Or use helper
$result = $connectionPool->execute(fn($conn) => $conn->query('SELECT ...'));

Anti-patterns to Avoid

Anti-patternProblemSolution
No ValidationReturning broken objectsValidate on acquire
No ResetState leaks between usesCall reset() on release
No TimeoutInfinite waitSet maxWaitTime
Unbounded PoolMemory exhaustionSet maxSize
Not ReleasingPool exhaustionUse try/finally
Wrong ScopePer-request poolsUse singleton/shared pool

References

For complete PHP templates and examples, see:

  • references/templates.md — All component templates
  • references/examples.md — ConnectionPool, HttpClientPool examples and tests

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Master backend architectures, REST API design, microservices, and server-side development across multiple languages. Use this as a central index to access specialized sub-skills.

日本語の概要は準備中です。原文の説明を表示しています。

MikeCheng1208/BattleTree22026年7月22日 更新

在每次回复中使用固定前缀并列出本次实际参考的指令/文件,便于校验是否遵循上下文与规则。

日本語の概要は準備中です。原文の説明を表示しています。

MikeCheng1208/BattleTree22026年7月22日 更新

Automate 21risk tasks via Rube MCP (Composio). Always search tools first for current schemas.

日本語の概要は準備中です。原文の説明を表示しています。

MikeCheng1208/BattleTree22026年7月22日 更新

Automate 2chat tasks via Rube MCP (Composio). Always search tools first for current schemas.

日本語の概要は準備中です。原文の説明を表示しています。

MikeCheng1208/BattleTree22026年7月22日 更新

Arquitecto de Soluciones Principal y Consultor Tecnológico de Andru.ia. Diagnostica y traza la hoja de ruta óptima para proyectos de IA en español.

日本語の概要は準備中です。原文の説明を表示しています。

MikeCheng1208/BattleTree22026年7月22日 更新

[00] META. Orchestrate skills into dynamic chains for complex tasks. Analyzes the task, discovers available skills, builds an optimal chain, explains why each skill is needed, and executes step-by-step with user confirmation. Use for any complex task requiring multiple thinking/research/analysis steps. Triggers on "plan this", "how to approach", "what's the strategy", "build a plan", or any multi-step problem requiring skill orchestration.

日本語の概要は準備中です。原文の説明を表示しています。

MikeCheng1208/BattleTree22026年7月22日 更新

MikeCheng1208 のスキルをすべて見る

このスキルの問題を報告する