PHP Classes

PHP Easy Cache: Cache the contents of remote pages in local files

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 286 All time: 7,543 This week: 206Up
Version Licenses PHP version Categories
php-easy-cache 1.2.2Freeware, MIT/X C...5.3.0PHP 5, Files and Folders, Cache
Description 

Author

This class can cache the contents of remote pages in local files.

It can retrieve the contents of a remote page with a given URL and store it in a local cache file, so next time the same page is requests it will retrieve from the cache file.

The cache file is stored with a given key name in a configurable cache directory. The cache expiry time is also configurable.

If the contents are in the JSON format, the class will return the decoded JSON value.

The class can also delete a given cached page or flush all expired cache files.

Picture of Hemn Chavroka
  Performance   Level  
Name: Hemn Chavroka <contact>
Classes: 1 package by
Country: Iran Iran
Age: 34
All time rank: 386980 in Iran Iran
Week rank: 215 Up2 in Iran Iran Up

Documentation

PHP EasyCache

The PHP EasyCache Class is an easy & fast way to cache 3rd party API calls with lossless data compression support.

Install

Install via composer:

{
    "require": {
        "iprodev/php-easycache": "~1.2"
    }
}

Run composer install then use as normal:

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

Usage

A very basic usage example:

$cache = new iProDev\Util\EasyCache();
$latest_tweet = $cache->get_data('tweet', 'http://search.twitter.com/search.atom?q=from:chawroka&rpp=1');
var_dump($latest_tweet);

A more advanced example:

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

$data = $cache->get('identity_keyword');

if(!$data) {
	$data = $cache->get_contents('http://some.api.com/file.json');
	$cache->set('identity_keyword', $data);
}

var_dump($data);

An example with compressing data:

$cache = new iProDev\Util\EasyCache();
$cache->compress_level = 9;

$data = $cache->get_data('identity_keyword', 'http://some.api.com/file.json');

var_dump($data);

API Methods

$data = "Some data to cache";

// Call EasyCache
$cache = new iProDev\Util\EasyCache();

// SET a Data into Cache
$cache->set('identity_keyword', $data);

// GET a Data from Cache
$data = $cache->get('identity_keyword');

// Check that the data is cached
$is_cached = $cache->is_cached('identity_keyword');

// Get the Data from URL and cache it
$data = $cache->get_data('identity_keyword', 'http://search.twitter.com/search.atom?q=from:chawroka&rpp=1');

// Helper function for retrieving data from url without cache
$data = $cache->get_contents('http://search.twitter.com/search.atom?q=from:chawroka&rpp=1');

// REMOVE a Cache item
$cache->delete('identity_keyword');

// REMOVES all Cache expired items
$cache->flush_expired();

// REMOVES all Cache items
$cache->flush();

Configuration

// Call EasyCache
$cache = new iProDev\Util\EasyCache();

// Path to cache folder (with trailing /)
$cache->cache_path = 'cache/';

// Cache file extension
$cache->cache_extension = '.cache';

// Length of time to cache a file (in seconds)
$cache->cache_time = 3600;

// Lossless data compression level. 1 - 9; 0 to disable
$cache->compress_level = 0;

Credits

PHP EasyCache was created by Hemn Chawroka from iProDev. Released under the MIT license.


  Files folder image Files (5)  
File Role Description
Files folder imagesrc (1 file)
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE.md Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (5)  /  src  
File Role Description
  Plain text file EasyCache.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:286
This week:0
All time:7,543
This week:206Up