PHP code example of linio / cache

1. Go to this page and download the library: Download linio/cache library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

linio / cache example snippets




use \Linio\Component\Cache\CacheService;

$container['cache'] = new CacheService([
    'namespace' => 'mx',
    'layers' => [
        0 => [
            'adapter_name' => 'array',
            'adapter_options' => [
                'cache_not_found_keys' => true,
                'encoder' => 'json',
            ],
        ],
        1 => [
            'adapter_name' => 'apc',
            'adapter_options' => [
                'ttl' => 3600,
            ],
        ],
        2 => [
            'adapter_name' => 'redis',
            'adapter_options' => [
                'host' => 'localhost',
                'port' => 6379,
                'ttl' => 0,
                'encoder' => 'serial',
            ],
        ],
    ],
]);

$container->setLogger($container['logger']);




$app['cache.service']->set('foo', 'bar');




    /**
     * @param string $key
     * @return string value
     */
    public function get($key);

    $adapter->get('foo');




     /**
     * @param array $keys
     * @return string[]
     */
    public function getMulti(array $keys);

    $adapter->getMulti(['foo', 'nop']);




     /**
     * @param string $key
     * @param string $value
     * @param ?int $ttl Time To Live; store value in the cache for ttl seconds.
     * This ttl overwrites the configuration ttl of the adapter
     * @return bool
     */
    public function set(string $key, $value, ?int $ttl = null);

    $adapter->set('foo', 'bar');
    $adapter->set('foo', 'bar', 60); // store bar in the cache for 60 seconds




     /**
     * @param array $keys
     * @return bool
     */
    public function setMulti(array $data);

    $adapter->setMulti(['foo' => 'bar', 'fooz' => 'baz']);




     /**
     * @param string $key
     * @return bool
     */
    public function delete($key);

    $adapter->delete('foo');




     /**
     * @param array $keys
     * @return bool
     */
    public function deleteMulti(array $keys);

    $adapter->deleteMulti(['foo', 'fooz']);




     /**
     * @param string $key
     * @return bool
     */
    public function contains($key);

    $adapter->contains('foo');




     /**
     * @return bool
     */
    public function flush();

    $adapter->flush();