API

This documentation is generated from PHPDOC.



Class: AhCache

Methoden verstecken

 __constructpublic __construct( $sModule = '.', $sCacheID = '.')
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

 _setupprivate _setup()
init
- load custom config from cache.class_config.php
- set a cache
- set remove file (if does not exist)
directory

 _getAllCacheDataprivate _getAllCacheData()
private function _getAllCacheData() - read cachedata and its meta infos
@since 2.0
@return array array with data, file stat

 _readCacheItemprivate _readCacheItem( $sFile) ... all param(s) required
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

 _getCacheFilenameprivate _getCacheFilename()
private function _getCacheFilename() - get full filename of cachefile
@return string full filename of cachefile

 _removeEmptyCacheDirprivate _removeEmptyCacheDir( $sDir, $bShowOutput = false) ... 1 of 2 param(s) required
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

 cleanuppublic cleanup( $iSec = false, $bShowOutput = false)
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

 getCachedItemspublic getCachedItems( $sDir = false, $aFilter = [])
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

 getCurrentModulepublic getCurrentModule()
get currently activated module
@since 2.6
@return string

 getCurrentIdpublic getCurrentId()
get current cache id
@since 2.6
@return string

 getModulespublic getModules()
get a flat array of module names that saved a cache item already
@since 2.5

@return array

 deletepublic 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

 deleteModulepublic deleteModule( $bShowOutput = false)
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

 dumppublic dump()
public function dump() - dump variables of cache class
@return true

 getAgepublic getAge()
public function getCacheAge() - get age in seconds of exisiting cachefile
@return int age in seconds; -1 if cachefiles does not exist

 getExpirepublic getExpire()
public function getExpire() - get TS of cache expiration
@since 2.0
@return int unix ts of cache expiration

 getRefFilepublic getRefFile()
public function getRefFile() - get reference file that invalidates the
cache item
@since 2.8
@return int get ttl of cache

 getTtlpublic getTtl()
public function getTtl() - get TTL of cache in seconds
@since 2.0
@return int get ttl of cache

 isExpiredpublic 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?

 iExpiredpublic 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

 isNewerThanFilepublic isNewerThanFile( $sRefFile = NULL)
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

 loadCachefilepublic loadCachefile( $sFile) ... all param(s) required
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

 readpublic read()
public function getCacheData() - read cachedata if it exist
@return various cachedata or false if cache does not exist

 removefileDeletepublic removefileDelete()
delete module based remove file
*
@since 2.6
@return boolean

 removefileTouchpublic removefileTouch()
make all cache items invalid by touching the remove file
*
@since 2.6
@return boolean

 setDatapublic setData( $data) ... all param(s) required
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

 setCacheIdpublic setCacheId( $sCacheID) ... all param(s) required
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

 setModulepublic setModule( $sModule, $sCacheID = false) ... 1 of 2 param(s) required
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

 setRefFilepublic setRefFile( $sFile) ... all param(s) required
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

 setTtlpublic setTtl( $iTtl) ... all param(s) required
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

 touchpublic touch()
public function touch() - touch cachefile if it exist
For cached data a new expiration based on existing ttl will be set
@return boolean

 writepublic write( $data = false, $iTtl = NULL, $sRefFile = NULL)
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

Properties verstecken

$sModulepublic $sModule = false
a module name string is used as relative cache path
@var string
$sCacheIDpublic $sCacheID = false
id of cachefile (filename will be generated from it)
@var string
$_sCacheDirprivate $_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
$_sCacheFileprivate $_sCacheFile = false
absolute filename of cache file
@var string
$_sCacheDirDividerprivate $_sCacheDirDivider = false
divider to limit count of cachefiles
@var type
$_sCacheExtprivate $_sCacheExt = cacheclass2
fileextension for storing cachefiles (without ".")
@var string
$_tsExpireprivate $_tsExpire = -1
Expiration timestamp;
It will be calculated with current time + ttl in the write() method
TTL can be read with getExpire()
@var integer
$_iTtlprivate $_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
$_aCacheInfosprivate $_aCacheInfos = false
cachedata and file infos of cachefile (returned array of php function stat)
@var array
$_sCacheRemovefileprivate $_sCacheRemovefile = false
Full path to a cache remove file for the current module
@var string
$_sRefFileprivate $_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






Copyright © 2009-2022 Axel Hahn
project page: GitHub (en)
Axels Webseite (de)
results will be here