msd Backup hinzugefügt

This commit is contained in:
aschwarz
2023-07-25 19:16:12 +02:00
parent 50297c1d25
commit 1d3ed789b5
680 changed files with 103120 additions and 0 deletions

View File

@ -0,0 +1,25 @@
# Apcu
Use [APCu cache](http://php.net/manual/en/book.apcu.php) to cache to shared
memory.
``` php
use Desarrolla2\Cache\Apcu as ApcuCache;
$cache = new ApcuCache();
```
_Note: by default APCu uses the time at the beginning of a request for ttl. In
some cases, like with a long running script, this can be a problem. You can
change this behaviour `ini_set('apc.use_request_time', false)`._
### Options
| name | type | default | |
| --------- | ---- | ------- | ------------------------------------- |
| ttl | int | null | Maximum time to live in seconds |
| prefix | string | "" | Key prefix |
### Packer
By default the [`NopPacker`](../packers/nop.md) is used.

View File

@ -0,0 +1,37 @@
# Chain
The Cache chain allows you to use multiple implementations to store cache. For
instance, you can use both fast volatile (in-memory) storage and slower
non-volatile (disk) storage. Alternatively you can have a local storage
as well as a shared storage service.
``` php
use Desarrolla2\Cache\Chain as CacheChain;
use Desarrolla2\Cache\Memory as MemoryCache;
use Desarrolla2\Cache\Predis as PredisCache;
$cache = new CacheChain([
(new MemoryCache())->withOption('ttl', 3600),
(new PredisCache())->withOption('ttl', 10800)
]);
```
The Chain cache implementation doesn't use any option. It uses the `Nop` packer
by default.
Typically it's useful to specify a maximum `ttl` for each implementation. This
means that the volatile memory only holds items that are used often.
The following actions propogate to all cache adapters in the chain
* `set`
* `setMultiple`
* `delete`
* `deleteMultiple`
* `clear`
For the following actions all nodes are tried in sequence
* `has`
* `get`
* `getMultiple`

View File

@ -0,0 +1,82 @@
# File
Save the cache as file to on the filesystem.
You must pass a cache directory to the constructor.
``` php
use Desarrolla2\Cache\File as FileCache;
$cache = new FileCache(sys_get_temp_dir() . '/cache');
```
### Options
| name | type | default | |
| ------------ | --------------------------------- | -------------- | ------------------------------------- |
| ttl | int | null | Maximum time to live in seconds |
| ttl-strategy | string ('embed', 'file', 'mtime') | "embed" | Strategy to store the TTL |
| prefix | string | "" | Key prefix |
| filename | string or callable | "%s.php.cache" | Filename as sprintf format |
#### TTL strategy option
The ttl strategy determines how the TTL is stored. Typical filesystems don't
allow custom file properties, so we'll have to use one of these strategies:
| strategy | |
| -------- | ----------------------------------------------- |
| embed | Embed the TTL as first line of the file |
| file | Create a TTL file in addition to the cache file |
| mtime | Use [mtime][] + max ttl |
The 'mtime' strategy is not PSR-16 compliant, as the TTL passed to the `set()`
method is ignored. Only the `ttl` option for is used on `get()` and `has()`.
[mtime]: https://www.unixtutorial.org/2008/04/atime-ctime-mtime-in-unix-filesystems/
#### Filename option
The `filename` will be parsed using `sprintf` where '%s' is substituted with
the key. The default extension is automatically determined based on the
packer.
Instead of a string, `filename` may also be set to a callable, like a callable
object or closure. In that case the callable will be called to create a
filename as
$filename = $callable($key);
##### BasicFilename
The library comes with invokable object as callable for the filename. The
`BasicFilename` object works as described above.
##### TrieFilename
The `TrieFilename` object will create a prefix tree directory structure. This
is useful where a lot of cache files would cause to many files in a directory.
Specify the `sprintf` format and the directory level to the constructor when
creating a `TrieFilename` object.
``` php
use Desarrolla2\Cache\File as FileCache;
use Desarrolla2\Cache\File\TrieFilename;
$callback = new TrieFilename('%s.php.cache', 2);
$cache = (new FileCache(sys_get_temp_dir() . '/cache'))
->withOption('filename', $callback);
```
In this case, adding an item with key `foobar` would be create a file at
/tmp/cache/f/fo/foobar.php.cache
### Packer
By default the [`SerializePacker`](../packers/serialize.md) is used. The
[`NopPacker`](../packers/nop.md) can be used if the values are strings.
Other packers, like the [`JsonPacker`](../packers/json.md) are also
useful with file cache.

View File

@ -0,0 +1,28 @@
# Memcached
Store cache to [Memcached](https://memcached.org/). Memcached is a high
performance distributed caching system.
``` php
use Desarrolla2\Cache\Memcached as MemcachedCache;
use Memcached;
$server = new Memcached();
// configure it here
$cache = new MemcachedCache($server);
```
This implementation uses the [memcached](https://php.net/memcached) php
extension. The (alternative) memcache extension is not supported.
### Options
| name | type | default | |
| --------- | ---- | ------- | ------------------------------------- |
| ttl | int | null | Maximum time to live in seconds |
| prefix | string | "" | Key prefix |
### Packer
By default the [`NopPacker`](../packers/nop.md) is used.

View File

@ -0,0 +1,23 @@
# Memory
Store the cache in process memory _(in other words in an array)_. Cache Memory
is removed when the PHP process exist. Also it is not shared between different
processes.
``` php
use Desarrolla2\Cache\Memory as MemoryCache;
$cache = new MemoryCache();
```
### Options
| name | type | default | |
| --------- | ---- | ------- | ------------------------------------- |
| ttl | int | null | Maximum time to live in seconds |
| limit | int | null | Maximum items in cache |
| prefix | string | "" | Key prefix |
### Packer
By default the [`SerializePacker`](../packers/serialize.md) is used.

View File

@ -0,0 +1,45 @@
# Mongo
Use it to store the cache in a Mongo database. Requires the mongodb extension
and the [mongodb/mongodb](https://github.com/mongodb/mongo-php-library)
library.
You must pass a `MongoDB\Collection` object to the cache constructor.
``` php
<?php
use Desarrolla2\Cache\Mongo as MongoCache;
use MongoDB\Client;
$client = new Client('mongodb://localhost:27017');
$database = $client->selectDatabase('mycache');
$collection = $database->selectCollection('cache');
$cache = new MongoCache($collection);
```
MonoDB will always automatically create the database and collection if needed.
### Options
| name | type | default | |
| --------- | ---- | ------- | ------------------------------------- |
| initialize | bool | true | Enable auto-initialize |
| ttl | int | null | Maximum time to live in seconds |
| prefix | string | "" | Key prefix |
#### Initialize option
If `initialize` is enabled, the cache implementation will automatically create
a [ttl index](https://docs.mongodb.com/manual/core/index-ttl/). In production
it's better to disable auto-initialization and create the ttl index explicitly
when setting up the database. This prevents a `createIndex()` call on each
request.
### Packer
By default the [`MongoDBBinaryPacker`](../packers/mongodbbinary.md) is used. It
serializes the data and stores it in a [Binary BSON variable](http://php.net/manual/en/class.mongodb-bson-binary.php).
If the data is a UTF-8 string of simple array or stdClass object, it may be
useful to use the [`NopPacker`](../packers/nop.md) instead.

View File

@ -0,0 +1,47 @@
# Mysqli
Cache to a [MySQL database](https://www.mysql.com/) using the
[mysqli](http://php.net/manual/en/book.mysqli.php) PHP extension.
You must pass a `mysqli` connection object to the constructor.
``` php
<?php
use Desarrolla2\Cache\Mysqli as MysqliCache;
$db = new mysqli('localhost');
$cache = new MysqliCache($db);
```
### Options
| name | type | default | |
| --------- | ---- | ------- | ------------------------------------- |
| initialize | bool | true | Enable auto-initialize |
| ttl | int | null | Maximum time to live in seconds |
| prefix | string | "" | Key prefix |
#### Initialize option
If `initialize` is enabled, the cache implementation will automatically create
a [scheduled event](https://dev.mysql.com/doc/refman/5.7/en/event-scheduler.html).
```
DELIMITER ;;
CREATE TABLE IF NOT EXISTS `cache` (`key` VARCHAR(255), `value` TEXT, `ttl` INT UNSIGNED, PRIMARY KEY (`key`));;
CREATE EVENT `apply_ttl_cache` ON SCHEDULE 1 HOUR
DO BEGIN
DELETE FROM `cache` WHERE `ttl` < NOW();
END;;
```
In production it's better to disable auto-initialization and create the event
explicitly when setting up the database. This prevents a `CREATE TABLE` and
`CREATE EVENT` query on each request.
### Packer
By default the [`SerializePacker`](../packers/serialize.md) is used.

View File

@ -0,0 +1,13 @@
# NotCache
A [Null object](https://sourcemaking.com/design_patterns/null_object) that
correctly implements the PSR-16 interface, but does not actually cache
anything.
``` php
use Desarrolla2\Cache\NotCache;
$cache = new NotCache();
```
It doesn't use any options or packers.

View File

@ -0,0 +1,74 @@
# PhpFile
Save the cache as PHP script to on the filesystem using
[`var_export`](http://php.net/manual/en/function.var-export.php) when storing
cache and [`include`](http://php.net/manual/en/function.include.php) when
loading cache.
The implementation leverages the PHP engines in-memory file caching (opcache)
to cache application data in addition to code. This method is particularly fast
in PHP7.2+ due to opcode cache optimizations.
PHP file caching should primarily be used for arrays and objects. There is no
performance benefit over APCu for storing strings.
[read more][]
``` php
use Desarrolla2\Cache\PhpFile as PhpFileCache;
$cache = new PhpFileCache();
```
### Options
| name | type | default | |
| --------- | ------------------ | -------------- | ------------------------------------- |
| ttl | int | null | Maximum time to live in seconds |
| prefix | string | "" | Key prefix |
| filename | string or callable | "%s.php" | Filename as sprintf format |
#### Filename option
The `filename` will be parsed using `sprintf` where '%s' is substituted with
the key.
Instead of a string, `filename` may also be set to a callable, like a callable
object or closure. In that case the callable will be called to create a
filename as
$filename = $callable($key);
##### BasicFilename
The library comes with invokable object as callable for the filename. The
`BasicFilename` object works as described above.
##### TrieFilename
The `TrieFilename` object will create a prefix tree directory structure. This
is useful where a lot of cache files would cause to many files in a directory.
Specify the `sprintf` format and the directory level to the constructor when
creating a `TrieFilename` object.
``` php
use Desarrolla2\Cache\File as FileCache;
use Desarrolla2\Cache\File\TrieFilename;
$callback = new TrieFilename('%s.php', 2);
$cache = (new FileCache(sys_get_temp_dir() . '/cache'))
->withOption('filename', $callback);
```
In this case, adding an item with key `foobar` would be create a file at
/tmp/cache/f/fo/foobar.php
### Packer
By default the [`NopPacker`](../packers/nop.md) is used. Other packers should
not be used.
[read more]: https://medium.com/@dylanwenzlau/500x-faster-caching-than-redis-memcache-apc-in-php-hhvm-dcd26e8447ad

View File

@ -0,0 +1,31 @@
# Predis
Cache using a [redis server](https://redis.io/). Redis is an open source,
in-memory data structure store, used as a database, cache and message broker.
You must provide a `Predis\Client` object to the constructor.
```php
use Desarrolla2\Cache\Predis as PredisCache;
use Predis\Client as PredisClient;
$client = new PredisClient('tcp://localhost:6379');
$cache = new PredisCache($client);
```
### Installation
Requires the [`predis`](https://github.com/nrk/predis/wiki) library.
composer require predis/predis
### Options
| name | type | default | |
| --------- | ---- | ------- | ------------------------------------- |
| ttl | int | null | Maximum time to live in seconds |
| prefix | string | "" | Key prefix |
### Packer
By default the [`SerializePacker`](../packers/serialize.md) is used.