PHP code example of ftembe / cachehandler

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

    

ftembe / cachehandler example snippets




use Ftembe\Cachehandler\Cachehandler;

jsonplaceholder.typicode.com/photos/')
{

    $curl = curl_init();

    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl, CURLOPT_URL, $endPoint);
    curl_setopt($curl,  CURLOPT_RETURNTRANSFER, true);

    $response = curl_exec($curl);

    if ($e = curl_error($curl))
        echo $e;

    curl_close($curl);

    return $response;
}

/*
You can create a folder to receive temporary data and pass it as a parameter when instantiating the CacheHandler class
eg. $cacheHandler = new Cachehandler('cacheFolder');
*/

$cacheHandler = new Cachehandler();

if ($cacheHandler->getDataLength('photos') != 5000){
    $store = $cacheHandler->store('photos', json_decode(fetchDataFromApi()), '1 hour');
}

$getDataLength = $cacheHandler->getDataLength('photos');
$getDataType = $cacheHandler->getDataType('photos');

$get = $cacheHandler->get('photos');


var_dump($get);
var_dump($getDataLength);
var_dump($getDataType);