Skip to content

Repository files navigation

Taggable PSR-6 cache pool

Latest Stable Version Coverage Software License

This package adds tag support to any PSR-6 cache pool. Native PHP Cache adapters already support tags and do not need this wrapper.

Installation

composer require cache/taggable-cache:^2.0

Usage

use Cache\Taggable\TaggablePSR6PoolAdapter;
use Symfony\Component\Cache\Adapter\ArrayAdapter;

$pool = TaggablePSR6PoolAdapter::makeTaggable(new ArrayAdapter());

$item = $pool->getItem('product.42');
$item->set(['name' => 'Desk'])->setTags(['products']);
$pool->save($item);

$pool->invalidateTag('products');

Install symfony/cache if you want to run this example. You can pass any PSR-6 pool to makeTaggable().

By default, tag metadata shares the wrapped pool. Pass a second PSR-6 pool when tag metadata needs separate storage.

saveDeferred() may persist immediately, as PSR-6 permits. This keeps the cached item and its tag metadata synchronized even if another caller commits the wrapped pool.

Native tag-list storage

Extend ExtensibleTaggablePSR6PoolAdapter when your tag store has native list operations. Its constructor and list methods are protected. makeTaggable() uses late static binding.

Override appendListItem(), removeListItem(), removeList(), and getList(). Use getCachePool() and getTagStorePool() to access the supplied PSR-6 pools.

The adapter keeps both wrapped pools private, so subclasses cannot replace them. The supplied tag-store object must expose its native list operations or native client through a subtype your subclass can recognize.

makeTaggable() returns an already-taggable cache pool unchanged when no separate tag store is supplied. Pass a separate tag store when the subclass hooks must run.

The three mutation methods return false when the tag store cannot update its index. The adapter reports that failure from the calling cache operation.

Contributing

Send pull requests to the main repository. Report issues on the GitHub issue tracker.

About

[READ-ONLY] A library to make a PSR-6 cache implementation taggable.

Resources

Stars

35 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages