Private Method Details |
fetch |
|
private string fetch( string $filePath )
|
| |
Fetch the data stream that was once pushed into the cache.
The $filePath is used in 2 ways :a) As key to identify the cache.b) See store()(If in store() you set: $originCheck==TRUE) the full path to the 'origin-file' is used to look up the mod-time.(If in store() you set: $originCheck==FALSE) $filePath is 'just' a key to identify the cach. No file look ups.
|
| Parameter |
|
| string |
$filePath |
|
|
the full path to the 'origin-file'. |
|
| Returns |
string The cached data on success OR NULL if data is out of date. |
| Throws |
FALSE on all errors. Check getLastError(). |
|
store |
|
private void store( string $filePath, string $dataStream, [ string $originCheck, string $maxLifeTime ] )
|
| |
Store the data stream to cache.
The $filePath is used in 2 ways :a) As key to identify the cache.b) (If $originCheck==TRUE) is the full path to the 'origin-file' to look up the mod-time.(If $originCheck==FALSE) *no* 'origin-file' is assumed, but $maxLifeTime should be setto a int > 0. If not it will default to 24 houres. You can set a default $maxLifeTimewith setCacheLifeTime() or indivitually by passing a parameter.The cache is considered 'out of date' (see fetch()) if one of following happens:a) $maxLifeTime has passed.b) The 'origin-file' changes (and $originCheck is set to TRUE)Done by comparing the modified times of the 'cache-file' and the 'origin file'as given by the parameter $filePath. If cache-file is eqal age oryounger, cache is considered 'up to date'Why the need for a max lifetime? You may think "we can check if the originalfile is older than the cache file, that's enough". lemme give you 2 reasons:1) If there is *no* origin file at all. That's the case when we cache somecalcuated data or something out of a database.2) The origin data, may it come from a real file or not, may include alifecycle. In my case the data is made up from an xml property file of aproduct in an eShop. Now that product may become alive or may become obsoletewithout that the original file changes, so that my crunching function comes up witha different result over time.
|
| Parameter |
|
| string |
$filePath |
|
|
the full path to the 'origin-file'. |
|
|
| string |
$dataStream |
|
|
the data to store. |
|
|
| string |
$originCheck |
= >>TRUE,<< |
|
(default: TRUE) If we should check if the origin has modified. If FALSE don't even assume an existing origin file. |
|
|
| string |
$maxLifeTime |
= >>NULL<< |
|
(default: see above). The max lifetime in secs for this cache. 0 = forever. NULL (default) = use the setting from setCacheLifeTime(). if nothing was set using setCacheLifeTime() then it's 0 (which means forever). |
|
| Returns |
void |
| Throws |
FALSE on all errors. Check getLastError(). |
| See Also |
setCacheLifeTime() |
|
clearBuffer |
|
private void clearBuffer( [ string $filePath ] )
|
| |
Clear the memory buffer (All or just one entry)
If the passed $filePath is not empty, the whole memory buffer is cleared.Otherwise only the entry matching $filePath is marked as invalid (if found)and will not be used any more. (That means it will reloaded from file)
|
| Parameter |
|
| string |
$filePath |
= >>''<< |
|
the full path to the 'origin-file'. |
|
| Returns |
void |
|
setBufferSize |
|
private int setBufferSize( mixed $newBufSize )
|
| |
Set the size of the cache buffer
Data that is sorted or fetched will be buffered up to the given size.When buffer is full the oldest entry(s) is kicked out.Default is 5% of the available memory as given by 'memory_limit' in the php.ini file.No buffering: If 'memory_limit' is not set or if you pass 0.Buffering with no limit: If you pass -1. (Of corse your not able to exceed PHP 'memory_limit')NOTE:It is possible that data of one entry is larger then the buffer limit.It will *NOT* be buffered then.PARAM:If numeric: We assume it as assumed to be absolute byte size.If string : May end with one of the usual unit endings e.g 'k', 'kb', 'M' (kilo-, mega-byte)If ending with '%' this means use x % of the available memory as given bymemory_limit in the php.ini file. But we never exceed 80%.
|
| Parameter |
|
| mixed |
$newBufSize |
|
|
(see above) |
|
| Returns |
int The set buffersize in byte. |
| Throws |
FALSE on error. (Buffer size is left unchanged) |
|
setBufferLifetime |
|
private void setBufferLifetime( [ integer $sec ] )
|
| |
The max time a memory buffered data is considered 'up to date' befor an 'up to date'-check
on the 'origin'-file is fired. Only active if there is an 'origin'-file in use.If the 'origin'-file has changed since a fetch() will return the 'out of date'-value NULL.(More doc in header).
|
| Parameter |
|
| integer |
$sec |
= >>10<< |
|
(default is 10s) |
|
| Returns |
void |
| See Also |
setCacheLifeTime() |
|
setCacheLifeTime |
|
private void setCacheLifeTime( [ integer $sec ] )
|
| |
The max time until the cached data is considered 'out to date' even if the 'origin'-file
hasn't changed. After this time a fetch() will return the 'out of date'-value NULL.Use if you want to limit the chache lifetime or when there is no 'origin'-file tocheck against (More doc in header).
|
| Parameter |
|
| integer |
$sec |
= >>0<< |
|
(default is 0 == 'no lifetime check'). See above. |
|
| Returns |
void |
| See Also |
setBufferLifetime() |
|
setDir |
|
private void setDir( [ string $path ] )
|
| |
Define where you want the cache-files to be stored.
If a valid path is passed all cache-files are stored in that dir. if the path does notexist yet, this method tries to create it.If called without param (or the dir is not writeable or not createable or whatever) asubdir called '_cache' will be created below the 'origin-file' dir and the cache-filesare stored there (default behavior, fallback too).
|
| Parameter |
|
| string |
$path |
= >>''<< |
|
(see above). |
|
| Returns |
void |
|
setVerboseCacheNames |
|
private void setVerboseCacheNames( [ string $trueFalse ] )
|
| |
Define if the 'cache-files' should contain a verbose name or not.
A verbose name contains the name of the 'origin-file' up to 100 chars.To keep the file unique, a md5-string is always appended to the chach-file.( The full path is taken to built the md5-string)
|
| Parameter |
|
| string |
$trueFalse |
= >>TRUE<< |
|
(see above). |
|
| Returns |
void |
|
getLastError |
|
private mixed getLastError( )
|
| |
Get last error.
|
| Returns |
mixed If last public fuction had an error, a string is returned otherwise FALSE. |
|
_getFiFoIndex |
|
private int _getFiFoIndex( $filePath )
|
| |
Find the index of the fifo-array matching $filePath
|
| Parameter |
|
|
$filePath |
|
|
Warning: documentation is missing. |
|
| Returns |
int The index (see above) |
| Throws |
FALSE if not found. |
|
_addToFiFo |
|
private bool _addToFiFo( array $cacheBlock )
|
| |
Add $cacheBlock to fifo-array
|
| Parameter |
|
| array |
$cacheBlock |
|
|
A data chunck |
|
| Returns |
bool TRUE if add succeded, otherwise FALSE |
|
_fifoFreeSpace |
|
private void _fifoFreeSpace( $sizeOfNewData )
|
| |
Free up the fifo-array until $sizeOfNewData fits in.
|
| Parameter |
|
|
$sizeOfNewData |
|
|
Warning: documentation is missing. |
|
| Returns |
void |
|
_fifoGarbageCollect |
|
private void _fifoGarbageCollect( )
|
| |
Get rid of entries in the fifo-array that are marked invalid
|
| Returns |
void |
|
_determinePathToCache |
|
private void _determinePathToCache( $filePath )
|
| |
Determine the cache-dir from the origin-dir and make the cache name.
Problems solved here:a) If 'verboseName' is TRUE then include the origin-name into the cache name.b) If 'storeDir' is set all cache-files are stored in one dir and have to be unique.c) Unique file names are achieved by appending a md5-stringMake unique name with md5(abs.path/origin-file)
|
| Parameter |
|
|
$filePath |
|
|
Warning: documentation is missing. |
|
| Returns |
void |
|
_isCacheFileUptodate |
|
private bool _isCacheFileUptodate( $filePath, $cacheFilePath )
|
| |
'Up To Date' - checking:
It is assumed that the passed 'data stream' has it's origin in data file thatwas crunched (or parsed or whatever) and that the cache is valid as long asthe 'origin-file' exits and is not modified.An 'Up To Date'-check compars the mod-time of the 'origin-file' against themod time of the 'cache-file'. If'origin-file-time' <= 'cache-file-time'the cache is consitered 'up to date'.The 'Up To Date' check takes place every time the 'cache-file' has to be loadedinto the memory buffer.
|
| Parameter |
|
|
$filePath |
|
|
Warning: documentation is missing. |
|
|
|
$cacheFilePath |
|
|
Warning: documentation is missing. |
|
| Returns |
bool TRUE on success. FALSE Otherwise. |
| Throws |
FALSE on all errors. Check getLastError(). |
|
_writeCacheFile |
|
private void _writeCacheFile( $cacheFilePath, $cacheBlock )
|
| |
Write cache
|
| Parameter |
|
|
$cacheFilePath |
|
|
Warning: documentation is missing. |
|
|
|
$cacheBlock |
|
|
Warning: documentation is missing. |
|
| Returns |
void |
| Throws |
FALSE on all errors. Check getLastError(). |
|
_readCacheFile |
|
private void _readCacheFile( $cacheFilePath )
|
| |
Read cache
|
| Parameter |
|
|
$cacheFilePath |
|
|
Warning: documentation is missing. |
|
| Returns |
void |
| Throws |
FALSE on all errors. Check getLastError(). |
|