Download the PHP package psr-discovery/cache-implementations without Composer
On this page you can find all versions of the php package psr-discovery/cache-implementations. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download psr-discovery/cache-implementations
More information about psr-discovery/cache-implementations
Files in psr-discovery/cache-implementations
Package cache-implementations
Short Description Lightweight library that discovers available PSR-6 Cache implementations by searching for a list of well-known classes that implement the relevant interface, and returns an instance of the first one that is found.
License MIT
Homepage https://github.com/psr-discovery
Informations about the package cache-implementations
Lightweight library that discovers available PSR-6 Cache implementations by searching for a list of well-known classes that implement the relevant interface, and returns an instance of the first one that is found.
This package is part of the PSR Discovery utility suite, which also supports PSR-18 HTTP Clients, PSR-17 HTTP Factories, PSR-14 Event Dispatcher, PSR-11 Containers and PSR-3 Logs.
This is largely intended for inclusion in libraries like SDKs that wish to support PSR-6 Caches without requiring hard dependencies on specific implementations or demanding extra configuration by users.
- Requirements
- Implementations
- Installation
- Usage
- Handling Failures
- Exceptions
- Singletons
- Mocking Priority
- Preferring an Implementation
- Using a Specific Implementation
Requirements
- PHP 8.1+
- Composer 2.0+
Successful discovery requires the presence of a compatible implementation in the host application. This library does not install any implementations for you.
Implementations
The following psr/cache-implementation
implementations are discovered and instantiated automatically:
- cache/apcu-adapter ^1.0
- cache/array-adapter ^1.0
- cache/void-adapter ^1.0
- tedivm/stash ^0.14
The following implementations can be discovered, but require manual instantiation due to their configuration requirements:
- apix/cache ^1.2
- cache/chain-adapter ^1.0
- cache/doctrine-adapter ^1.0
- cache/filesystem-adapter ^1.0
- cache/memcache-adapter ^1.
- cache/memcached-adapter ^1.0
- cache/mongodb-adapter ^1.0
- cache/predis-adapter ^1.0
- cache/redis-adapter ^1.0
- laminas/laminas-cache ^2.8 | ^3.0
- matthiasmullie/scrapbook ^1.0
- neos/cache ^4.0
- psx/cache ^1.0
- symfony/cache ^3.1 | ^4.0 | ^5.0 | ^6.0 | ^7.0
- symfony/symfony ^3.1.4 | ^4.0 | ^5.0 | ^6.0 | ^7.0
- tedivm/stash ^0.14
The following mock implementations are also available:
If a particular implementation is missing that you'd like to see, please open a pull request adding support.
Installation
Usage
You can also use Discover::caches()
to retrieve an array with all discovered implementations. This is useful if you want to support implementations that can't be instantiated without configuration.
Handling Failures
If the library is unable to discover a suitable PSR-6 implementation, the Discover::cache()
discovery method will simply return null
. This allows you to handle the failure gracefully, for example by falling back to a default implementation.
Example:
Singletons
By default, the Discover::cache()
method will always return a new instance of the discovered implementation. If you wish to use a singleton instance instead, simply pass true
to the $singleton
parameter of the discovery method.
Example:
Mocking Priority
This library will give priority to searching for a known, available mocking library before searching for a real implementation. This is to allow for easier testing of code that uses this library.
The expectation is that these mocking libraries will always be installed as development dependencies, and therefore if they are available, they are intended to be used.
Preferring an Implementation
If you wish to prefer a specific implementation over others, you can prefer()
it by package name:
This will cause the cache()
method to return the preferred implementation if it is available, otherwise, it will fall back to the default behavior.
Note that assigning a preferred implementation will give it priority over the default preference of mocking libraries.
Using a Specific Implementation
If you wish to force a specific implementation and ignore the rest of the discovery candidates, you can use()
its package name:
This will cause the cache()
method to return the preferred implementation if it is available, otherwise, it will return null
.
This library is not produced or endorsed by, or otherwise affiliated with, the PHP-FIG.