PHP code example of ugurcsen / phpeasycache

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

    

ugurcsen / phpeasycache example snippets





use EasyCache\Cache;
$cache = new Cache();
$cache->saveLocation = '/var/temp'; //Should be changed for operating system but not necessary


use EasyCache\CacheElement;
$data = "Something which needs to cached.";
$dataCache = $cache->createElement('data1', 540);// Key , ExpiresTime(seconds)
$dataCache->save($data);//If data caching before expires date, Nothing will save


$cachedData = $dataCache->get();//Getting cached data
if($cachedData != null){
	echo $cachedData;
}


if($dataCache->check()){//Checking cached data is exsist
	echo $dataCache->get();
}


$dataCache->clear();//Deleting cached data


use EasyCache\Cache;
use EasyCache\CacheElement;
$cache = new Cache();

$data = "Something which needs to cached.";
$dataCache = $cache->createElement('data1', 540);
$dataCache->save($data);//If data caching before expires date, Nothing will save

if($dataCache->check()){
	echo $dataCache->get();
}

$dataCache->clear();


use EasyCache\Cache;
$cache = new Cache();
$data = "Something which needs to cached.";
//Creating
$cache->set('data1', 540, $data);//If data caching before expires date, Nothing will save
//Getting and writing
if($cache->checkWithKey('data1')){
  echo $cache->getWithKey('data1');
}
//Deleting
$cache->clearWithKey('data1');

PHP >= 7.4