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


$config = [
    'settings' => [
        'cache' => [
            'engine' => \WebSK\Cache\Engines\Memcache::class,
            'cache_key_prefix' => 'skif',
            'servers' => [
                [
                    'host' => 'memcached',
                    'port' => 11211
                ]
            ]
        ]
    ]
];

/**
 * @param ContainerInterface $container
 * @return CacheService
 */
$container['cache_service'] = function (ContainerInterface $container) {
    $cache_config = $container["settings"]["cache"];
    
    $cache_servers_arr = [];
    foreach ($cache_config['servers'] as $server_config) {
        $cache_servers_arr[] = new CacheServerSettings($server_config['host'], $server_config['port']);
    }

    /** @var CacheEngineInterface $cache_engine_class_name */
    $cache_engine_class_name = $cache_config['engine'];
    $cache_engine = new $cache_engine_class_name($cache_servers_arr, $cache_config['cache_key_prefix']);

    return new CacheService($cache_engine);
};