W3cubDocs

/Phalcon 3

Class Phalcon\Cache\Multiple

Source on GitHub

Allows to read to chained backend adapters writing to multiple backends

use Phalcon\Cache\Frontend\Data as DataFrontend;
use Phalcon\Cache\Multiple;
use Phalcon\Cache\Backend\Apc as ApcCache;
use Phalcon\Cache\Backend\Memcache as MemcacheCache;
use Phalcon\Cache\Backend\File as FileCache;

$ultraFastFrontend = new DataFrontend(
    [
        "lifetime" => 3600,
    ]
);

$fastFrontend = new DataFrontend(
    [
        "lifetime" => 86400,
    ]
);

$slowFrontend = new DataFrontend(
    [
        "lifetime" => 604800,
    ]
);

//Backends are registered from the fastest to the slower
$cache = new Multiple(
    [
        new ApcCache(
            $ultraFastFrontend,
            [
                "prefix" => "cache",
            ]
        ),
        new MemcacheCache(
            $fastFrontend,
            [
                "prefix" => "cache",
                "host"   => "localhost",
                "port"   => "11211",
            ]
        ),
        new FileCache(
            $slowFrontend,
            [
                "prefix"   => "cache",
                "cacheDir" => "../app/cache/",
            ]
        ),
    ]
);

//Save, saves in every backend
$cache->save("my-key", $data);

Methods

public __construct ([Phalcon\Cache\BackendInterface[] $backends])

Phalcon\Cache\Multiple constructor

public push (Phalcon\Cache\BackendInterface $backend)

Adds a backend

public mixed get (string | int $keyName, [int $lifetime])

Returns a cached content reading the internal backends

public start (string | int $keyName, [int $lifetime])

Starts every backend

public save ([string $keyName], [string $content], [int $lifetime], [boolean $stopBuffer])

Stores cached content into all backends and stops the frontend

public boolean delete (string | int $keyName)

Deletes a value from each backend

public exists ([string | int $keyName], [int $lifetime])

Checks if cache exists in at least one backend

public flush ()

Flush all backend(s)

© 2011–2017 Phalcon Framework Team
Licensed under the Creative Commons Attribution License 3.0.
https://docs.phalconphp.com/en/latest/api/Phalcon_Cache_Multiple.html