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 for 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
@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; delete all cachefiles older than n seconds
Other filetypes in the 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 = Array)
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

 deletepublic delete()
public function delete - delete a single cache item if it exist
@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

 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);
@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) ... all param(s) required
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

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

 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

 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 = -1)
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 time in s if content cache expires (min. 0)
@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






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