2017 © Pedro Peláez
 

library php-cache-class

A simple file based cache based from Erik Giberti's FileCache class, forked from lodev09/php-cache-class.

image

rothkj1022/php-cache-class

A simple file based cache based from Erik Giberti's FileCache class, forked from lodev09/php-cache-class.

  • Tuesday, July 3, 2018
  • by rothkj1022
  • Repository
  • 1 Watchers
  • 0 Stars
  • 14 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

PHP FileCache Class (File base)

A simple file based cache based from Erik Giberti's FileCache class. See here, (*1)

Enhanced Features

  • Data is serialized and JSON encoded
  • Cache data is encrypted by mcrypt
  • File Based Cache was explained here

Installation

Run the following command in your command line shell in your php project, (*2)

$ composer require rothkj1022/php-cache-class

Done., (*3)

You may also edit composer.json manually then perform composer update:, (*4)

"require": {
    "rothkj1022/php-cache-class": "^2.1.0"
}

Getting started

Example usage with composer

//load composer packages
require('vendor/autoload.php');

//create new instance of the class
use rothkj1022\FileCache;
$cache = new FileCache\FileCache("tmp/");

Example usage without composer

//require the class
require_once("lib/FileCache.php");

//create new instance of the class
use rothkj1022\FileCache;
$cache = new FileCache\FileCache("tmp/");

//...

Local file source example

$cache_key = "client_list";

//see if we can get an existing cache
if (!$clients_data = $cache->get($cache_key)) {
    //nope. Let's get the real one!
    $clients_data = json_decode(file_get_contents("clients.json"));

    //set the cache up!
    $expire = 3600; //1 hour
    $cache->set($cache_key, $clients_data, $expire);
}

var_dump($clients_data);

External http GET request example

$uri = 'https://raw.githubusercontent.com/bahamas10/css-color-names/master/css-color-names.json';
$remote_data = $cache->file_get_contents($uri);
var_dump($remote_data);

Reference

Code reference for you to get started!, (*5)

Properties

  • protected $root = '/tmp/'; - Value is pre-pended to the cache, should be the full path to the directory.
  • protected $error = null; - For holding any error messages that may have been raised
  • private $_encryption_key = 'Fil3C@ch33ncryptionK3y' - Main key used for encryption (you need to set this up inside the class)

Methods

Public Methods

  • Cache::get($key) - Reads the data from the cache specified by the cache key
  • Cache::set($key [, $data, $ttl]) - Saves data to the cache. Anything that evaluates to false, null, '', boolean false, 0 will not be saved. $ttl Specifies the expiry time
  • Cache::delete($key) - Deletes the cache specified by the $key
  • Cache::get_error() - Reads and clears the internal error
  • Cache::have_error() - Can be used to inspect internal error

Private Methods

See code to see all private methods used like Cache::_encrypt($pure_string) etc., (*6)

Changelog

Version 2.1.3

  • Fixed: Stopped echoing guzzle request errors to screen

Version 2.1.2

  • Integrated guzzle for more efficient http get requests

Version 2.1.1

  • Changed: Renamed class back to Erik Giberti's original name, FileCache

Version 2.1.0

  • Added: Composer integration
  • Added: changelog

Credits

2010 - Authored by Erik Giberti 2011-2014 - Rewritten by Jovanni Lo / @lodev09 2018 - Modified by Kevin Roth / @rothkj1022, (*7)

License

Released under the MIT License. See LICENSE file., (*8)

The Versions

03/07 2018

dev-master

9999999-dev

A simple file based cache based from Erik Giberti's FileCache class, forked from lodev09/php-cache-class.

  Sources   Download

MIT

The Requires

 

03/07 2018

2.1.3

2.1.3.0

A simple file based cache based from Erik Giberti's FileCache class, forked from lodev09/php-cache-class.

  Sources   Download

MIT

The Requires

 

18/06 2018

2.1.2

2.1.2.0

A simple file based cache based from Erik Giberti's FileCache class, forked from lodev09/php-cache-class.

  Sources   Download

MIT

The Requires

 

12/06 2018

2.1.1

2.1.1.0

A simple file based cache based from Erik Giberti's FileCache class, forked from lodev09/php-cache-class.

  Sources   Download

MIT

The Requires

  • php ^5.2 || ^7.0

 

12/06 2018

2.1.0

2.1.0.0

A simple file based cache based from Erik Giberti's FileCache class, forked from lodev09/php-cache-class.

  Sources   Download

MIT

The Requires

  • php ^5.2 || ^7.0