PHP Cache Class
require '/yourpath/Strcache.php';
$url="https://xxxx";
$fctNewRequest = function() use ($url){
return @file_get_contents($url);
};
/*
If the cache is older than 5 minutes, the user function is called to update the cache.
In the other case, the content is taken from the cache file.
*/
$strContent = strCache::create($fctNewRequest,'cachefile.dat')->getContent("5 Min");
Info | Value |
---|---|
Declaration | class Strcache |
Datei | Strcache.php |
Date/Time modify File | 2021-06-08 10:42:14 |
File-Size | 4938 Byte |
MD5 File | 1748923e2c6e41f8c24ce9ffa8c2f88b |
Version | 1.2 |
Methods and Parameter | Description/Comments |
---|---|
public function __construct($fct,$fileName = null) | create new strcache object param $fct callbackfunktion, must return new content as string param $fileName filename for cachefile (default strcache.dat) |
public static function create($fct,$fileName = null) | create a new Object |
public function setCallbackFunction($fct) | set a new function to fetch content |
public function setCacheFileName($fileName) | set new CacheFile |
public function getContent($maxAge = "0 Sec") | maxAge: string rel. DateTime or numeric (Seconds) return Cache as string, "" if error if Cache older as maxAge, $fct called to fetch new Content More see Method Status |
public function clear() | cache file delete return true if delete ok or file not exists |
public function status() | return cache status -1: Status Unknown 0: Clear 1: New, $fct was called succesfull for new Content or after refresh or setContent 2: Normal 3: Old, $fct was called with error for new Content |
public function dateTimeModify() | return DateTime Modify Cache or false if Cachefile not exists or Error |
Declaration/Name | Value | Description/Comments |
---|---|---|
const CACHE_UNKNOWN = -1; | -1 | |
const CACHE_EMPTY = 0; | 0 | |
const CACHE_NEW = 1; //$fct was called | 1 | $fct was called |
const CACHE_NORMAL = 2; | 2 | |
const CACHE_OLD = 3; //$fct was called with error | 3 | $fct was called with error |
const CACHE_ERROR = 4; | 4 |