This documentation is generated from PHPDOC.
__construct | public | __construct( constructor @param string $sModule name of module or app that uses the cache @param string $sCacheID cache-id (must be uniq within a module; used to generate filename of cachefile) @return boolean | |
_setup | private | _setup() init - load custom config from cache.class_config.php - set a cache - set remove file (if does not exist) directory | |
_getAllCacheData | private | _getAllCacheData() private function _getAllCacheData() - read cachedata and its meta infos @since 2.0 @return array array with data, file stat | |
_readCacheItem | private | _readCacheItem( read a raw cache item and return it as hash * @param string $sFile filename with full path or relative to cache base path @return array|boolean | |
_getCacheFilename | private | _getCacheFilename() private function _getCacheFilename() - get full filename of cachefile @return string full filename of cachefile | |
_removeEmptyCacheDir | private | _removeEmptyCacheDir( helper function - remove empty cache directories up to module cache dir * @param string $sDir @param boolean $bShowOutput flag: show output? default: false (=no output) @return void | |
cleanup | public | cleanup( Cleanup cache directory; It deletes all outdated cache items of current module. Additionally you can delete all cachefiles older than n seconds (because there are cache items that are not based on a TTL). Other filetypes in the cache directory won't be touched. Empty directories will be deleted. Only the directory of the initialized module/ app will be deleted. $o=new Cache("my-app"); $o->cleanup(60*60*24*3); To delete all cachefles of all modules you can use $o=new Cache(); $o->cleanup(0); @since 2.0 @param int $iSec max age of cachefile; older cachefiles will be deleted @param boolean $bShowOutput flag: show output? default: false (=no output) @return true | |
getCachedItems | public | getCachedItems( get an array with cached data elements @since 2.4 * @param string $sDir full path of cache dir; default: false (auto detect cache dir) @param array $aFilter filter; valid keys are - ageOlder integer return items that are older [n] sec - lifetimeBelow integer return items that expire in less [n] sec (or outdated) - lifetimeGreater integer return items that expire in more than [n] sec - ttlBelow integer return items with ttl less than [n] sec - ttlGreater integer return items with ttl more than [n] sec no filter returns all cached entries @return void | |
getCurrentModule | public | getCurrentModule() get currently activated module @since 2.6 @return string | |
getCurrentId | public | getCurrentId() get current cache id @since 2.6 @return string | |
getModules | public | getModules() get a flat array of module names that saved a cache item already @since 2.5 @return array | |
delete | public | delete() delete a single cache item if it exist. It returns true if a cache item was deleted. It returns false if it does not exist (yet) or the deletion failed. @return boolean | |
deleteModule | public | deleteModule( delete all existing cached items of the set module Remark: this method should be used in an admin interface or cronjob only. It makes a recursive filesystem scan and is quite slow. @since 2.6 @param boolean $bShowOutput flag: show output? default: false (=no output) @return boolean | |
dump | public | dump() public function dump() - dump variables of cache class @return true | |
getAge | public | getAge() public function getCacheAge() - get age in seconds of exisiting cachefile @return int age in seconds; -1 if cachefiles does not exist | |
getExpire | public | getExpire() public function getExpire() - get TS of cache expiration @since 2.0 @return int unix ts of cache expiration | |
getRefFile | public | getRefFile() public function getRefFile() - get reference file that invalidates the cache item @since 2.8 @return int get ttl of cache | |
getTtl | public | getTtl() public function getTtl() - get TTL of cache in seconds @since 2.0 @return int get ttl of cache | |
isExpired | public | isExpired() public function isExpired() - cache expired? To check it you must use ttl while writing data, i.e. $oCache->write($sData, [$iTtl, [RefFile]]); A cache item is expired if - the module remove file is newer - if a ttl was set: the min. ttl @since 2.0 @return bool cache is expired? | |
iExpired | public | iExpired() public function iExpired() - get time in seconds when cachefile expires you must use ttl while writing data, i.e. $oCache->write($sData, $iTtl); @since 2.1 @return int expired time in seconds; negative if cache is not expired | |
isNewerThanFile | public | isNewerThanFile( function isNewerThanFile($sRefFile) - is the cache (still) newer than a reference file? This function returns difference of mtime of both files. @since 2.0 @param string $sRefFile local filename @return integer time in sec how much the cache file is newer; negative if reference file is newer | |
loadCachefile | public | loadCachefile( load cache item from a given file - this is like reverse engineering by reading data file; needed for a admin interface only @since 2.6 @param string $sFile filename with full path @return boolean | |
read | public | read() public function getCacheData() - read cachedata if it exist @return various cachedata or false if cache does not exist | |
removefileDelete | public | removefileDelete() delete module based remove file * @since 2.6 @return boolean | |
removefileTouch | public | removefileTouch() make all cache items invalid by touching the remove file * @since 2.6 @return boolean | |
setData | public | setData( public function setData($data) - set cachedata into cache object data can be any serializable type, like string, array or object Remark: You additionally need to call the write() method to store data in the filesystem @since 2.0 @param various $data data to store in cache @return boolean | |
setCacheId | public | setCacheId( set new cache id; it keeps current module @param string $sCacheID cache-id (must be uniq within a module; used to generate filename of cachefile) adding the cache id is recommendet, otherwise you addiionally need to call setCacheId() @return boolean | |
setModule | public | setModule( set module @param string $sModule name of module or app that uses the cache @param string $sCacheID optional: cache-id (must be uniq within a module; used to generate filename of cachefile) adding the cache id is recommendet, otherwise you addiionally need to call setCacheId() @return boolean | |
setRefFile | public | setRefFile( public function setRefFile() - set a reference file that invalidates the cache if the file is newer than the stored item @since 2.8 @param int $iTtl ttl value in seconds @return int get ttl of cache | |
setTtl | public | setTtl( public function setTtl() - set TTL of cache in seconds You need to write the cache data to ap Remark: You additionally need to call the write() method to store a new ttl value with data in the filesystem @since 2.0 @param int $iTtl ttl value in seconds @return int get ttl of cache | |
touch | public | touch() public function touch() - touch cachefile if it exist For cached data a new expiration based on existing ttl will be set @return boolean | |
write | public | write( Write data into a cache. - data can be any serializable type, like string, array or object - set ttl in s (from now); optional parameter @param various $data data to store in cache @param int $iTtl optional: time in s if content cache expires (min. 0) @param string $sRefFile optional: set a reference file that invalidates the cache if it is newer @return bool success of write action |
$sModule | public | $sModule = false a module name string is used as relative cache path @var string |
$sCacheID | public | $sCacheID = false id of cachefile (filename will be generated from it) @var string |
$_sCacheDir | private | $_sCacheDir = false where to store all cache data - it can be outside docRoot. If it is below docRoot think about forbidding access If empty it will be set in the constructor to [webroot]/~cache/ or $TEMP/~cache/ for CLI @var string |
$_sCacheFile | private | $_sCacheFile = false absolute filename of cache file @var string |
$_sCacheDirDivider | private | $_sCacheDirDivider = false divider to limit count of cachefiles @var type |
$_sCacheExt | private | $_sCacheExt = cacheclass2 fileextension for storing cachefiles (without ".") @var string |
$_tsExpire | private | $_tsExpire = -1 Expiration timestamp; It will be calculated with current time + ttl in the write() method TTL can be read with getExpire() @var integer |
$_iTtl | private | $_iTtl = -1 TTL (time to live) in s; TTL can be set in methods setTtl($iTtl) or write($data, $iTtl) TTL can be read with getTtl() @var integer |
$_aCacheInfos | private | $_aCacheInfos = false cachedata and file infos of cachefile (returned array of php function stat) @var array |
$_sCacheRemovefile | private | $_sCacheRemovefile = false Full path to a cache remove file for the current module @var string |
$_sRefFile | private | $_sRefFile = false Reference file: a cache is outdated if the reference file is newer than the cache item. TTL can be set in methods setRefFile($sFile) or write($data, $iTtl, $sFile) TTL can be read with getRefFile() @var string |