Cache

Cache comes integrated to the framework, powered by phpFastCache.

Storage types supported: Redis, Predis, Cookie, Files, MemCache, MemCached, APC, WinCache, X-Cache and PDO with SQLite

Usage

Add the use statement at the beginning of your php file and call the Cache class:

use Amostajo\WPPluginCore\Cache;

Getting a value

$value = Cache::get( 'mykey' );

Cache existance

$flag = Cache::has( 'mykey' );

Adding a value

Adding a value to cache will required an expiration time in minutes. This value will determine when the cache should clear the value from storage:

Cache::add( 'mykey', $value, $expiresAtMinute = 10 );

Function remember() is a flexible way of adding and retrieving cache values, it receives as second parameter the interval in which the value in cache should be refreshed and the Closure to refresh to:

$value = Cache::remember( 'mykey', $refreshAtMinute = 10, function () {
    return $new_value;
} );

Deleting a value

Cache::forget( 'mykey );

Empty cache

The following method will remove all cache values:

Cache::flush();

Cache configuration

Cache can be configured in the template’s configuration file.  It is recommended to read phpFastCache documentation first.

Disable

Cache can be disabled in the template’s configuration file.