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 TaggablePSR6PoolAdapter when your tag store has native list operations. The constructor and list methods are protected, and makeTaggable() uses late static binding.

Override appendListItem(), removeListItem(), removeList(), and getList(). Keep the native client in your subclass. The adapter does not expose either wrapped pool as mutable subclass state.

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