Documentation

CacheItemPool
in package
implements CacheItemPoolInterface uses ValidatesKey

PSR-6 cache item pool class

Tags
category

Pop

author

Nick Sagona, III nick@popphp.org

copyright

Copyright (c) 2009-2026 Nick Sagona, III

license

https://www.popphp.org/license New BSD License

version
5.0.0

Table of Contents

Interfaces

CacheItemPoolInterface

Properties

$adapter  : AdapterInterface
Cache adapter
$deferred  : array<string|int, mixed>
Deferred cache items, keyed by item key

Methods

__construct()  : mixed
Constructor
__destruct()  : void
Destructor
clear()  : bool
Clear all stored values from cache
commit()  : bool
Persist all deferred cache items
deleteItem()  : bool
Delete an item from the cache
deleteItems()  : bool
Delete multiple items from the cache
getItem()  : CacheItem
Get a cache item by key
getItems()  : iterable<string|int, mixed>
Get multiple cache items by their keys
hasItem()  : bool
Determine if the cache contains an item for the given key
save()  : bool
Persist a cache item immediately
saveDeferred()  : bool
Queue a cache item to be persisted later
validateKey()  : void
Validate a cache key (throws on reserved characters or an empty string)

Properties

$deferred

Deferred cache items, keyed by item key

protected array<string|int, mixed> $deferred = []

Methods

__destruct()

Destructor

public __destruct() : void

Ensure any deferred cache items are persisted before the pool is destroyed, per PSR-6 §1.4 ("A Pool MUST ensure that any deferred cache items are eventually persisted"). A destructor must never let an exception escape, so failures here are swallowed.

clear()

Clear all stored values from cache

public clear() : bool
Return values
bool

commit()

Persist all deferred cache items

public commit() : bool
Return values
bool

deleteItems()

Delete multiple items from the cache

public deleteItems(array<string|int, mixed> $keys) : bool
Parameters
$keys : array<string|int, mixed>
Tags
throws
InvalidArgumentException
Return values
bool

getItems()

Get multiple cache items by their keys

public getItems([array<string|int, mixed> $keys = [] ]) : iterable<string|int, mixed>
Parameters
$keys : array<string|int, mixed> = []
Tags
throws
InvalidArgumentException
Return values
iterable<string|int, mixed>

hasItem()

Determine if the cache contains an item for the given key

public hasItem(string $key) : bool
Parameters
$key : string
Tags
throws
InvalidArgumentException
Return values
bool

save()

Persist a cache item immediately

public save(CacheItemInterface $item) : bool

A resolved expiration of zero or negative seconds deletes the item instead of caching it permanently, since the underlying adapter's saveItem() treats a TTL of 0 as "never expires" — the opposite of what an already-expired item should do.

Parameters
$item : CacheItemInterface
Tags
throws
InvalidArgumentException
Return values
bool

saveDeferred()

Queue a cache item to be persisted later

public saveDeferred(CacheItemInterface $item) : bool
Parameters
$item : CacheItemInterface
Tags
throws
InvalidArgumentException
Return values
bool

validateKey()

Validate a cache key (throws on reserved characters or an empty string)

protected validateKey(string $key) : void
Parameters
$key : string
Tags
throws
InvalidArgumentException

        
On this page

Search results