Simple cache for storing data like as loader classes.

The preferred way to install this extension is through composer.

$ composer require braunmar/simplecache

Or add:

"braunmar/simplecache": "*"

To the require section of your composer.json file. Then rune:

$ composer update

Just simple use:

use braunmar\simple\cache\SimpleCache;

// you can pass config in constructor
$cache = new braunmar\simple\cache\SimpleCache();

// config
$cache->config([
    'path' => __DIR__ . '/some/path',
    'filename' => 'filename',
    'type' => 'php',
    // ...
]);

// cache something
$cache->cache(['key1' => 'value1', 'key2' => 'value2']);
// load cache data
$data = $cache->load();

Note:

This class can by used with braunmar/simple/classloader/ClassLoader class.

  • filename:string Filename where data is stored.
  • minify:boolean Minify style.
  • path:string Path of file where data is stored.
  • type:array Type which the data is stored.

Note:

All options can by set in constructor or via config method as associative array. All options can by set via setter and return actual value via getter.

  • TYPE_PHP:string Store in PHP format.
  • TYPE_JSON:string Store in JSON format.
  • TYPE_SERIALIZE:string Store in serialize format.
  • TYPES:array All supported types. Array of constants: TYPE_PHP, TYPE_JSON, TYPE_SERIALIZE.

The class supports these methods:

config

Set options as associative array.

$cache->config([
    'minify' => true,
    'path' => __DIR__,
    'type' => SimpleCache::TYPE_JSON,
    'filename' => 'cachedData',
    // ...
]);

cache

Cache data. Supported types: array, string, int, float

$cache->cache($data);

load

Load cached data from file.

$cache->load();

Simple cache is under MIT licence. See the LICENSE for details.