PHP code example of mattmezza / cacheasy

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

    

mattmezza / cacheasy example snippets


$providerStrAPI = new class implements Cacheasy\StringProvider {
    public function get() : string
    {
        return (new SlowAPIsClient())->slowAPI();
    }
};
// ./cache is the cache path, 86400 is the time to live
$cache = new Cache("./cache", 86400);
// if slowAPI is not cached let's get the data and cache them
$result = $cache->getString("slowAPI", $providerStrAPI); # this is slow :(
$result2 = $cache->getString("slowAPI", $providerStrAPI); # this is blazing fast :)
echo $result2;

$providerJsonAPI = new class implements Cacheasy\JsonProvider {
    public function get() : array
    {
        return (new SlowAPIsClient())->slowAPI();
    }
};
// ./cache is the cache path, 86400 is the time to live
$cache = new Cache("./cache", 86400);
// if slowAPI is not cached let's get the data and cache them
$result = $cache->getJson("slowjsonAPI", $providerJsonAPI); # this is slow :(
$result2 = $cache->getJson("slowjsonAPI", $providerJsonAPI); # this is blazing fast :)
echo $result2["property"];