PHP code example of dc / cache

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

    

dc / cache example snippets


$cache = new \SomeImplementation();
$cache->set('foo', 'bar');
echo $cache->get('foo'); // prints bar

echo $cache->getWithFallback('foo', function() {
  return 'bar';
}); // prints bar
$cache->get('foo'); // now also prints bar

$foo = $cache->getWithFallback("foo", 
    function($x) { return ["foo" => $x, "expires" => \DateInterval($x)]; }, 
    function($result) { return $result["expires"]; });