PHP code example of horde / memcache

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

    

horde / memcache example snippets


use Horde\Memcache\{MemcacheApi, Config};

$config = new Config(
    hostspec: ['127.0.0.1'],
    port: [11211],
    prefix: 'myapp_'
);

$cache = new MemcacheApi($config);

// PSR-16 interface (standard)
$cache->set('key', 'value', 3600);
$value = $cache->get('key', 'default');
$cache->delete('key');

// Horde Extended interface (large items, multi-key)
$cache->setLarge('report', $hugeData, 3600);  // >1MB OK
$values = $cache->getItems(['k1', 'k2', 'k3']);
$cache->deleteDelayed('lock', 30);