Download the PHP package koded/cache-simple without Composer
On this page you can find all versions of the php package koded/cache-simple. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package cache-simple
Koded - Simple Caching Library
A PSR-16 caching library for PHP 8 using several caching technologies. It supports JSON caching for Redis.
Requirements
The library is not tested on any Windows OS and may not work as expected there.
The recommended installation method is via Composer
Redis
There are two client flavors for Redis by using the
and they are not mutually exclusive.
These clients supports JSON serialization for the cache, useful for handling the cached data in other programming languages.
Since there is no Redis native support for JSON serialization, it's done in userland and that always introduces some overhead. Be aware that the native PHP and Igbinary functions are superior.
- the
RedisClient
is preferred if Redis extension is installed - the
PredisClient
can be used otherwise
Memcached
Please install the Memcached extension.
Usage
The factory function always creates a new instance of specific
SimpleCacheInterface
client implementation.
A bit verbose construction for the same instance is
Configuration directives
Current available configuration classes
- RedisConfiguration
- MemcachedConfiguration
- FileConfiguration
- PredisConfiguration
RedisConfiguration
Please refer to Redis extension connect method.
Parameter | Value |
---|---|
host | 127.0.0.1 |
port | 6379 |
timeout | 0.0 |
reserved | null |
retry | 0 |
Serializers
php
(default)json
The special config directive is
binary(string)
for setting the internal serializer functions to either PHP nativeun/serialize()
,igbinary_un/serialize()
ormsgpack_un/pack()
.
The binary
directive is effective if igbinary
and/or msgpack
extensions are installed and loaded.
Otherwise it defaults to PHP un/serialize()
functions.
You can change the binary flag on already cached data, but you should invalidate the previously cached items, since they are already serialized and stored in the cache.
JSON serializer options
The default options for json_encode() function are:
- JSON_PRESERVE_ZERO_FRACTION
- JSON_UNESCAPED_SLASHES
- JSON_THROW_ON_ERROR
To set the desired options, use the options
configuration directive:
JSON options are applied with bitmask operators. The above example will
- remove
JSON_UNESCAPED_SLASHES
(because it's already set) - add
JSON_FORCE_OBJECT
MemcachedConfiguration
Memcached arguments | Type | Required | Description |
---|---|---|---|
id | string | no | Memcached persistent_id value |
servers | array | no | A list of nested array with [server, port] values |
options | array | no | A list of Memcached options |
ttl | int | no | Global TTL (in seconds) |
The following options are set by default when an instance of MemcachedConfiguration
is created,
except for OPT_PREFIX_KEY
which is there as a reminder that it may be set.
Memcached option | Default value |
---|---|
OPT_DISTRIBUTION | DISTRIBUTION_CONSISTENT |
OPT_SERVER_FAILURE_LIMIT | 2 |
OPT_REMOVE_FAILED_SERVERS | true |
OPT_RETRY_TIMEOUT | 1 |
OPT_LIBKETAMA_COMPATIBLE | true |
OPT_PREFIX_KEY | null |
Options with
NULL
value will be removed.
There are many Memcached options that may suit the specific needs for the caching scenarios and this is something the developer/s needs to figure it out.
Examples:
PredisConfiguration
By default the parameters are:
Parameter | Value |
---|---|
scheme | tcp |
host | 127.0.0.1 |
port | 6379 |
Examples:
There are many configuration options for this package. Please refer to Predis configuration page.
Shared Memory (shmop)
Requires a PHP shmop extension.
FileConfiguration
Please avoid it on production environments, or use it as a last option.
If cache directory is not provided in the configuration, the PHP function sys_get_temp_dir() is used to store the cached files in the OS "temporary" directory.
MemoryClient
This client will store the cached items in the memory for the duration of the script's lifetime. It is useful for development, but not for production.
MemoryClient
is also the default client if you do not require a specific client incache_simple_factory()
Code quality
or
Benchmarks
The benchmarks are flaky and dependant on the environment. This table gives a non-accurate insight how client performs at write-read-delete operations, and should have an informative comparison.
To find out what may be the fastest choice for your environment, run
License
The code is distributed under the terms of The 3-Clause BSD license.
All versions of cache-simple with dependencies
koded/stdlib Version ^6.3
psr/simple-cache Version ^3.0
psr/log Version ^3
ext-json Version *