Skip to content

trafficinc/php-easycache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PHP Easy Cache

An easy way to cache 3rd party API calls with PHP.

Install - Composer

{
    "require": {
        "trafficinc/php-easycache": "~1.0"
    }
}

Then include composer autoloader

require 'vendor/autoload.php';
$cache = new Trafficinc\Util\EasyCache();

Usage

$cache = new Trafficinc\Util\EasyCache();
$cache->cache_path = 'cache/';
$cache->cache_time = 3600;

if($data = $cache->get_cache('label')){
	$data = json_decode($data);
} else {
	$data = $cache->do_request('https://jsonplaceholder.typicode.com/posts/1');
	$cache->set_cache('label', $data);
	$data = json_decode($data);
}

print_r($data);

Clear the Cache

// clear single cache file by id
$cache->clear('label');
// clear whole cache
$cache->clear();

About

An easy way to cache 3rd party API calls with PHP.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages