PHP code example of websk / php-cache

1. Go to this page and download the library: Download websk/php-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/ */

    

websk / php-cache example snippets


use WebSK\Cache\Engines\Memcached;

$config = [
    'settings' => [
        'cache' => [
            'engine' => Memcached::class,
            'cache_key_prefix' => 'websk',
            'servers' => [
                [
                    'host' => 'memcached',
                    'port' => 11211,
                ],
            ],
        ],
    ],
];

use WebSK\Cache\CacheServiceProvider;

CacheServiceProvider::register($container);

$cache = CacheServiceProvider::getCacheService($container);
$cache->set('user-42', ['name' => 'Alice'], 300);
$user = $cache->get('user-42');

use WebSK\Cache\CacheWrapper;

CacheWrapper::setContainer($container);
$value = CacheWrapper::get('user-42');