Claude-skill-registry acc-create-object-pool
Generates Object Pool pattern for PHP 8.5. Creates reusable object containers for expensive resources like connections. Includes unit tests.
install
source · Clone the upstream repo
git clone https://github.com/majiayu000/claude-skill-registry
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/acc-create-object-pool" ~/.claude/skills/majiayu000-claude-skill-registry-acc-create-object-pool && rm -rf "$T"
manifest:
skills/data/acc-create-object-pool/SKILL.mdsource content
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/
— Generic pool contract with acquire/releasePoolInterface.php
— Configuration value object (min/max size, timeouts)PoolConfig.php
— Contract for poolable objects (reset, isValid, close)PoolableInterface.php
— Generic pool implementationObjectPool.php
— Wrapper tracking usage metricsPooledObject.php
— Exception for exhausted poolPoolExhaustedException.php
— Exception for invalid objectsInvalidPoolObjectException.php
Step 2: Generate Specialized Pool (if needed)
Path:
src/Infrastructure/{Domain}/
— Specialized pool (ConnectionPool, HttpClientPool){Type}Pool.php
— Poolable implementation for specific resourcePoolable{Type}.php
Step 3: Generate Tests
Path:
tests/Unit/Infrastructure/Pool/
— Core pool functionality testsObjectPoolTest.php
— Specialized pool tests{Type}PoolTest.php
File Placement
| Component | Path |
|---|---|
| Pool Interface | |
| Pool Implementation | |
| Specialized Pools | |
| Unit Tests | |
Naming Conventions
| Component | Pattern | Example |
|---|---|---|
| Interface | | |
| Implementation | | |
| Poolable Interface | | |
| Config | | |
| Wrapper | | |
| Specialized Pool | | |
| Test | | |
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-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:
— All component templatesreferences/templates.md
— ConnectionPool, HttpClientPool examples and testsreferences/examples.md