2017 © Pedro Peláez
 

library cache

Simplest cache implementation ever!

image

kminek/cache

Simplest cache implementation ever!

  • Friday, February 23, 2018
  • by kminek
  • Repository
  • 1 Watchers
  • 1 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 13 % Grown

The README.md

Cache

This is really simple filesystem cache implementation which should work on broad range of PHP versions. Just plug and play - perfect solution for tiny projects and quick scripts where you do not need full-blown cache solutions., (*1)

Installation

$ composer require kminek/cache

API

/**
 * @param string $key
 * @param mixed  $default
 *
 * @return mixed
 */
function cache_get($key, $default = null);

/**
 * @param string   $key
 * @param mixed    $value
 * @param null|int $ttl
 *
 * @return bool
 */
function cache_set($key, $value, $ttl = null);

/**
 * @param string $key
 *
 * @return bool
 */
function cache_delete($key);

/**
 * @return bool
 */
function cache_clear();

Usage

require 'vendor/autoload.php';

$cachedData = cache_get('cachedData');

if (!$cachedData) {
    echo 'Saving cache...' . PHP_EOL;
    cache_set('cachedData', array('lorem', 'ipsum'), 5 * 60); // 5 minutes
} else {
    echo 'Data retrieved from cache!' . PHP_EOL;
    var_dump($cachedData);
}

Advanced usage

// set your custom configuration options (below are default ones)
Kminek_Cache::configure(array(
    'engine' => Kminek_Cache::ENGINE_SERIALIZE, // or Kminek_Cache::ENGINE_JSON or Kminek_Cache::ENGINE_VAR_EXPORT
    'dir' => sys_get_temp_dir(), // where to store cache files
    'prefix' => 'kminek_cache',
    'separator' => '_',
    'extension' => '.cache',
    'ttl' => 60 * 60, // default ttl in seconds (1 hour)
));

// then use cache as you would normally do
$cachedData = cache_get('cachedData');
...

The Versions

23/02 2018

dev-master

9999999-dev https://github.com/kminek/cache

Simplest cache implementation ever!

  Sources   Download

MIT

cache

23/02 2018

v2.0.0

2.0.0.0 https://github.com/kminek/cache

Simplest cache implementation ever!

  Sources   Download

MIT

cache

22/02 2018

v1.0.0

1.0.0.0 https://github.com/kminek/cache

Simplest cache implementation ever!

  Sources   Download

MIT

cache