acc-create-object-pool

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

181 stars

Best use case

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

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

Teams using acc-create-object-pool 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-object-pool/SKILL.md --create-dirs "https://raw.githubusercontent.com/majiayu000/claude-skill-registry/main/skills/data/acc-create-object-pool/SKILL.md"

Manual Installation

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

How acc-create-object-pool Compares

Feature / Agentacc-create-object-poolStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Generates Object Pool pattern for PHP 8.5. Creates reusable object containers for expensive resources like connections. 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

# Object Pool Pattern Generator

Creates Object Pool pattern infrastructure for managing reusable expensive objects.

## When to Use

| Scenario | Example |
|----------|---------|
| Expensive creation | Database connections |
| Limited resources | HTTP client handles |
| Connection reuse | Socket connections |
| Memory management | Large 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

| Component | Path |
|-----------|------|
| Pool Interface | `src/Infrastructure/Pool/` |
| Pool Implementation | `src/Infrastructure/Pool/` |
| Specialized Pools | `src/Infrastructure/{Domain}/` |
| Unit Tests | `tests/Unit/Infrastructure/Pool/` |

---

## Naming Conventions

| Component | Pattern | Example |
|-----------|---------|---------|
| Interface | `PoolInterface` | `PoolInterface` |
| Implementation | `ObjectPool` | `ObjectPool` |
| Poolable Interface | `PoolableInterface` | `PoolableInterface` |
| Config | `PoolConfig` | `PoolConfig` |
| Wrapper | `PooledObject` | `PooledObject` |
| Specialized Pool | `{Type}Pool` | `ConnectionPool` |
| Test | `{ClassName}Test` | `ObjectPoolTest` |

---

## Quick Template Reference

### PoolInterface

```php
/**
 * @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

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

### PoolConfig

```php
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

```php
// 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-pattern | Problem | Solution |
|--------------|---------|----------|
| No Validation | Returning broken objects | Validate on acquire |
| No Reset | State leaks between uses | Call reset() on release |
| No Timeout | Infinite wait | Set maxWaitTime |
| Unbounded Pool | Memory exhaustion | Set maxSize |
| Not Releasing | Pool exhaustion | Use try/finally |
| Wrong Scope | Per-request pools | Use 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

Related Skills

accessibility-object-model-integration

181
from majiayu000/claude-skill-registry

Programmatic manipulation of the accessibility tree to support complex custom controls in React.

acc-create-value-object

181
from majiayu000/claude-skill-registry

Generates DDD Value Objects for PHP 8.5. Creates immutable, self-validating objects with equality comparison. Includes unit tests.

acc-create-use-case

181
from majiayu000/claude-skill-registry

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-unit-test

181
from majiayu000/claude-skill-registry

Generates PHPUnit unit tests for PHP 8.5. Creates isolated tests with AAA pattern, proper naming, attributes, and one behavior per test. Supports Value Objects, Entities, Services.

acc-create-test-double

181
from majiayu000/claude-skill-registry

Generates test doubles (Mocks, Stubs, Fakes, Spies) for PHP 8.5. Creates appropriate double type based on testing needs with PHPUnit MockBuilder patterns.

acc-create-test-builder

181
from majiayu000/claude-skill-registry

Generates Test Data Builder and Object Mother patterns for PHP 8.5. Creates fluent builders with sensible defaults and factory methods for test data creation.

acc-create-strategy

181
from majiayu000/claude-skill-registry

Generates Strategy pattern for PHP 8.5. Creates interchangeable algorithm families with context class, strategy interface, and concrete implementations. Includes unit tests.

acc-create-state

181
from majiayu000/claude-skill-registry

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-specification

181
from majiayu000/claude-skill-registry

Generates DDD Specification for PHP 8.5. Creates reusable business rule objects for validation, filtering, and querying with composite pattern support. Includes unit tests.

acc-create-saga-pattern

181
from majiayu000/claude-skill-registry

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

181
from majiayu000/claude-skill-registry

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

acc-create-responder

181
from majiayu000/claude-skill-registry

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