Skip to content
acc-create-object-pool logo

Object Pool Pattern Generator

acc-create-object-pool

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

SKILL.md

Full skill instructions

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

More DevOps & CI/CD skills

Project scaffolding, deployment configuration, and CI/CD setup for Google ADK agents.

6K 472.6K
View

Set up tracing, logging, and monitoring for deployed ADK agents across Cloud Trace, BigQuery, and third-party platforms.

6K 472.6K
View

Enterprise Azure infrastructure architect generating Bicep or Terraform from workload descriptions.

1.5K 454.3K
View
azure-kubernetes logo
DevOps & CI/CD

azure-kubernetes

Plan and configure production-ready Azure Kubernetes Service clusters with Day-0 and Day-1 best practices.

1.5K 447.1K
View

Raw mechanical interfaces fusing Swiss typographic print with military terminal aesthetics. Rigid grids, extreme type scale contrast, utilitarian color, analog degradation effects. For data-heavy dashboards, portfolios, or editorial sites that need to feel like declassified blueprints.

92.7K 354.9K
View
just-scrape logo
DevOps & CI/CD

just-scrape

Web search, scraping, extraction, crawling, and monitoring via ScrapeGraph AI CLI.

69 245K
View

Skill for working with Firebase Hosting (Classic). Use this when you want to deploy static web apps, Single Page Apps (SPAs), or simple microservices. Do NOT use for Firebase App Hosting.

462 159.7K
View

Deploy and manage web apps with Firebase App Hosting. Use this skill when deploying Next.js/Angular apps with backends.

462 159.1K
View
deploy-to-vercel logo
DevOps & CI/CD

deploy-to-vercel

Deploy applications and websites to Vercel. Use when the user requests deployment actions like "deploy my app", "deploy and give me the link", "push this live", or "create a preview deployment".

31.9K 146.6K
View
programmatic-seo logo
DevOps & CI/CD

programmatic-seo

Build SEO-optimized pages at scale using templates, data, and proven playbook patterns.

53.3K 140.1K
View

Design and build isolated, reusable Convex backend components with clear boundaries and app-facing wrappers.

63 123.5K
View

Deploy and manage projects on Vercel using token-based authentication. Use when working with Vercel CLI using access tokens rather than interactive login — e.g. "deploy to vercel", "set up vercel", "add environment variables to vercel".

31.9K 116.1K
View

Coding & apps AI tools

Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View
I
Coding & apps

Imagica

Build a no-code AI app in minutes.

Freemium
View
E
Coding & apps

Emergent.sh

An IDE for code migration from legacy to modern frameworks through coding agents.

Freemium
View
Wonder Dynamics logo
Coding & apps

Wonder Dynamics

Automate CGI animation in live-action scenes

Paid
View
M
Coding & apps

Mixo

Launch a website in seconds with AI.

Paid
View
AI Code Convert logo
Coding & apps

AI Code Convert

Streamline Your Coding Experience with AI Code Helper

Free
View