PHP code example of serato / cacheable-array

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

    

serato / cacheable-array example snippets


use Serato\CacheableArray\CacheableArray;

// Use any cache that implements `Psr\SimpleCache\CacheInterface`
$cache = new \Symfony\Component\Cache\Simple\FilesystemCache;

// Create the CacheableArray instance
$ac = new CacheableArray($cache, 'my_cache_key');

// Use standard PHP array syntax for accessing, counting or iterating over the CacheableArray instance
$ac['key'] = 'value';
echo $ac['key'];
echo count($ac);
foreach ($ac as $k => $v) {
    echo $v;
}
unset($ac['key']);

use Serato\CacheableArray\CacheableArray;

// Create a CacheableArray with a cache TTL of seconds
$ac = new CacheableArray($cache, 'my_cache_key', 60);

// Change cache TTL to 300 seconds
$ac->setTTL(300);