To use PHPCache, just include the class.
include_once"PHPCache.php";
After that you can instanciate a PHPCache object and pass the configuration.
$options = array(
"filePath" => "temp",
"lifeTime" => "2024",
"fileExtension" => "txt"
);
$cache = new PHPCache($options);
The filePath parameter referes to a directory where PHPCache can create folders (write permission!).
The lifeTime parameter tells PHPCache how long it should keep some cached data before it will be deleted.
The fileExtension parameter is optional. If none is passed, PHPCache will use .txt - but you should use some extension your webserver doesn't serve or at least configure your webserver in a way that nobody can access these files (.htaccess!)
Now you can save variables.
$var = "Please save me before someone unsets me :D";
$identifer = $cache->save($var);
unset($var);
$var = $cache->get($identifer);
echo $var;
This code example saves some variable and reads it and assigns it afterwards.
$identifer holds an identifer which refers to the data. You need this in order to restore the data from cache.
You can pass an optional parameter $ownIdentifer to the save method. PHPCache will use this identifer. (You can use function calls as a string in order to cache functions)
You can use the isResource($identifer) method to control if data is still available.
You can use the remove($identifer) method to remove data by hand. Normally you don't need this because outdated data will be deleted automatically.
You can use the extendLifetime($identifer, $newLifeTime) method to increase the lifetime of cached data. The lifetime will start at the time of the call.
Setters & Getters
setTempFilePath($filepath)
getTempFilePath()
setLifeTime($lifeTime)
getLifeTIme()