PHP code example of dercoder / simple-cache-shared-memory
1. Go to this page and download the library: Download dercoder/simple-cache-shared-memory 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/ */
dercoder / simple-cache-shared-memory example snippets
use DerCoder\SimpleCache\SharedMemory\SharedMemoryCache;
use Psr\SimpleCache\CacheInterface;
$cache = new SharedMemoryCache('1M'); // 1MB shared memory segment
// Set cache items
$cache->set('key1', 'value1');
$cache->set('key2', [1, 2, 3], 60); // with TTL of 60 seconds
// Get cache items
$value1 = $cache->get('key1');
$value2 = $cache->get('key2');
// Check if a cache item exists
$hasKey1 = $cache->has('key1');
// Delete cache items
$cache->delete('key1');