Skip to content

Repository files navigation

Memcached PSR-6 cache pool

Latest Stable Version Coverage Software License

This package provides PSR-6 and PSR-16 cache implementations backed by the Memcached extension. The pool supports tags and hierarchical keys.

Installation

Install the package and enable the Memcached extension:

composer require cache/memcached-adapter:^3.0

Usage

use Cache\Adapter\Memcached\MemcachedCachePool;

$client = new Memcached();
$client->addServer('127.0.0.1', 11211);

$pool = new MemcachedCachePool($client);

The pool enables Memcached's binary protocol by default. Pass a Memcached option map as the second constructor argument to override it or set other client options:

$pool = new MemcachedCachePool($client, [
    Memcached::OPT_BINARY_PROTOCOL => false,
    Memcached::OPT_CONNECT_TIMEOUT => 1000,
]);

Bulk operations

The PSR-16 getMultiple(), setMultiple(), and deleteMultiple() methods use the native Memcached bulk commands. Bulk writes keep the same expiration for every value and remove old tag references after storage succeeds.

The pool treats false from Memcached's getMulti() as a backend failure. It throws CachePoolException instead of returning a batch of cache misses.

Upgrading to version 3

Version 3 stores a generation snapshot with each tagged item and a separate marker for each tag. Version 2 workers cannot safely share this format.

The constructor now accepts a Memcached option map instead of a Boolean binary-protocol flag.

Stop or drain all workers, clear Memcached, and then deploy version 3. Follow the same sequence before a rollback.

Contributing

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

About

[READ-ONLY] Memcached PSR-6 Cache pool

Resources

Stars

16 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages