Download the PHP package websk/php-cache without Composer
On this page you can find all versions of the php package websk/php-cache. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download websk/php-cache
More information about websk/php-cache
Files in websk/php-cache
Package php-cache
Short Description Cache abstraction with optional Memcache, Memcached, and Redis backends
License MIT
Informations about the package php-cache
WebSK php-cache
A small cache abstraction for PHP applications with optional Memcache, Memcached, and Redis backends.
Requirements
- PHP 8.3 or newer, including PHP 8.5
psr/container1.1 or 2.0- One backend client selected by the application
The base package does not install a backend client. Install only the backend used by the application:
| Engine | Additional requirement |
|---|---|
WebSK\Cache\Engines\Memcache |
PHP memcache extension |
WebSK\Cache\Engines\Memcached |
PHP memcached extension |
WebSK\Cache\Engines\Redis |
composer require predis/predis:^3.7 |
Installation
Install and enable either ext-memcache or ext-memcached through the PHP extension manager available in the deployment environment. For Redis, install Predis in the application:
Configuration
Select the engine class and provide its servers:
Each server must have a string host and an integer port. An empty cache_key_prefix uses default when cache keys are generated.
When the Redis engine receives one server, it creates a normal Predis connection. Multiple servers use Predis client-side clustering unless explicit cluster, replication, or aggregate options are passed to the Redis constructor.
Container registration
The service provider requires a container that implements both Psr\Container\ContainerInterface and ArrayAccess. Settings are read from the PSR-11 settings entry, while the cache service factory is registered through array access.
CacheWrapper can be used after assigning the same PSR-11 container:
Cache behavior
get()returnsfalsefor a cache miss or unavailable backend.- Consequently, a stored boolean
falsecannot be distinguished from a cache miss. - TTL
0means no expiration. - Negative TTL values are rejected by every engine.
- Memcache and Memcached accept relative TTL values below 30 days; values of 30 days or more are rejected by this library.
- Redis serializes values before storing them and accepts any non-negative TTL.
- Keys are hashed with MD5 after the configured prefix is applied.
Development
Run syntax checks, PHPUnit, and PHPStan level max with: