PHP code example of benjamindean / one-line-apc

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

    

benjamindean / one-line-apc example snippets



$cache = new OneLineAPC();

$cache = new OneLineAPC('apcu');

$cache->setTtl(3600);

$cache->setCache($dataToCache, 'key', 3600);

$cache->cached('key', 'functionName');

$cache->cached('key', array($obj, 'functionName'));

class ReturnData {
    public function fetchData($url) {
        return file_get_contents($url);
    }
}

$obj = new ReturnData();

$apc = new OneLineAPC();
$apc->setTtl(3600);

return $apc->cached('key', array($obj, 'fetchData'), array('http://example.com/'));


function fetchData($url) {
    return file_get_contents($url);
}

$apc = new OneLineAPC();
$apc->setTtl(3600);

return $apc->cached('key', 'fetchData', array('http://example.com/'));


$something = 'Data to be cached';

$apc = new OneLineAPC();

return $apc->cached('key', $something, false, 3600);