Source for file Container.php
Documentation is available at Container.php 
// +----------------------------------------------------------------------+  
// +----------------------------------------------------------------------+  
// | Copyright (c) 1997-2003 The PHP Group                                |  
// +----------------------------------------------------------------------+  
// | This source file is subject to version 2.0 of the PHP license,       |  
// | that is bundled with this package in the file LICENSE, and is        |  
// | available at through the world-wide-web at                           |  
// | http://www.php.net/license/2_02.txt.                                 |  
// | If you did not receive a copy of the PHP license and are unable to   |  
// | obtain it through the world-wide-web, please send a note to          |  
// | license@php.net so we can mail you a copy immediately.               |  
// +----------------------------------------------------------------------+  
// | Authors: Ulf Wendel <ulf.wendel@phpdoc.de>                           |  
// |          Sebastian Bergmann <sb@sebastian-bergmann.de>               |  
// |          Christian Stocker <chregu@phant.ch>                         |  
// +----------------------------------------------------------------------+  
// $Id: Container.php,v 1.9 2008/10/07 09:04:49 dufuz Exp $  
require_once 'Cache/Error.php';   
* Common base class of all cache storage container.  
* To speed up things we do a preload you should know about, otherwise it might  
* play you a trick. The Cache controller classes (Cache/Cache, Cache/Output, ...)  
* usually do something like is (isCached($id) && !isExpired($id)) return $container->load($id).  
* if you implement isCached(), isExpired() and load() straight ahead, each of this  
* functions will result in a storage medium (db, file,...) access. This generates too much load.  
* Now, a simple speculative preload should saves time in most cases. Whenever  
* one of the mentioned methods is invoked we preload the cached dataset into class variables.  
* That means that we have only one storage medium access for the sequence  
*  (isCached($id) && !isExpired($id)) return $container->load($id).  
* The bad thing is that the preloaded data might be outdated meanwhile, which is  
* unlikely but for you power users, be warned. If you do not want the preload  
* you should switch it off by setting the class variable $preload to false. Anyway, this is  
* @author   Ulf Wendel <ulf.wendel@phpdoc.de>  
* @version  $Id: Container.php,v 1.9 2008/10/07 09:04:49 dufuz Exp $  
    * Flag indicating wheter to preload datasets.  
    * See the class description for more details.  
    * ID of a preloaded dataset  
    * Cache group of a preloaded dataset  
    * Expiration timestamp of a preloaded dataset.  
    * @var  integer 0 means never, endless  
    * Value of a preloaded dataset.  
    * Preloaded userdata field.  
    * Flag indicating that the dataset requested for preloading is unknown.  
    * Encoding mode for cache data: base64 or addslashes() (slash).  
    * @var  string  base64 or slash  
    * Highwater mark - maximum space required by all cache entries.  
    * Whenever the garbage collection runs it checks the amount of space  
    * required by all cache entries. If it's more than n (highwater) bytes  
    * the garbage collection deletes as many entries as necessary to reach the  
    * Options that can be set in every derived class using it's constructor.  
    * Loads a dataset from the cache.  
    * @param    string  dataset ID  
    * @param    string  cache group  
    * @return   mixed   dataset value or null on failure  
    function load($id, $group)  
            if ($this->id !=  $id ||  $this->group !=  $group) {  
        $ret =  $this->fetch($id, $group);   
        if (PEAR ::isError ($ret)) {  
    * Returns the userdata field of a cached data set.  
    * @param    string  dataset ID  
    * @param    string  cache group  
    * @return   string  userdata  
            if ($this->id !=  $id ||  $this->group !=  $group) {  
        $ret =  $this->fetch($id, $group);   
        if (PEAR ::isError ($ret)) {  
        list ( , , $userdata) =  $ret;  
    } // end func getUserdata  
    * Checks if a dataset is expired.  
    * @param    string  dataset ID  
    * @param    string  cache group  
    * @param    integer maximum age timestamp  
            if ($this->id !=  $id ||  $this->group !=  $group) {  
            // check if at all it is cached  
            $ret =  $this->fetch($id, $group);   
            if (PEAR ::isError ($ret)) {  
        if ($expired  =  ($this->expires <=  time() ||  ($max_age &&  ($this->expires <=  $max_age))) ) {  
    * Checks if a dataset is cached.  
    * @param    string  dataset ID  
    * @param    string  cache group  
            if ($this->id !=  $id ||  $this->group !=  $group) {  
    * Fetches a dataset from the storage medium.  
    * @param    string  dataset ID  
    * @param    string  cache group  
    * @return   array   format: [expire date, cached data, user data]  
    function fetch($id, $group)  
        return array (null , null , null );   
    * @param    string  dataset ID  
    * @param    mixed   data to store  
    * @param    mixed   userdefined expire date  
    * @param    string  cache group  
    * @param    string  additional userdefined data  
    function save($id, $data, $expire, $group, $userdata)  
        // QUESTION: Should we update the preload buffer instead?  
        // Don't think so as the sequence save()/load() is unlikely.  
    * @param    string  dataset ID  
    * @param    string  cache group  
    * Flushes the cache - removes all caches datasets from the cache.  
    * @param    string      If a cache group is given only the group will be flushed  
    * @return   integer     Number of removed datasets, -1 on failure  
    * Checks if a dataset exists.  
    * @param    string  dataset ID  
    * @param    string  cache group  
    * Starts the garbage collection.  
    } // end func garbageCollection  
    * Does a speculative preload of a dataset  
    * @param    string  dataset ID  
    * @param    string  cache group  
        // whatever happens, remember the preloaded ID  
        $ret =  $this->fetch($id, $group);   
        if (PEAR ::isError ($ret)) {  
    * Flushes the internal preload buffer.  
    * save(), remove() and flush() must call this method  
    * to preevent differences between the preloaded values and  
    * the real cache contents.  
    * @param    string  dataset ID, if left out the preloaded values will be flushed.  
    *                    If given the preloaded values will only be flushed if they are  
    *                    equal to the given id and group  
    * @param    string  cache group  
        if (!$id ||  ($this->id ==  $id &&  $this->group ==  $group)) {  
            // clear the internal preload values  
    } // end func flushPreload  
    * Imports the requested datafields as object variables if allowed  
    * @param    array   List of fields to be imported as object variables  
    * @param    array   List of allowed datafields  
        foreach ($allowed as  $k =>  $field) {  
            if (isset ($requested[$field])) {  
                $this->$field =  $requested[$field];   
    * Encodes the data for the storage container.  
    * @var  mixed data to encode  
    * Decodes the data from the storage container.  
    * Translates human readable/relative times in unixtime  
    * @param  mixed   can be in the following formats:  
    *                human readable          : yyyymmddhhmm[ss]] eg: 20010308095100  
    *                relative in seconds (1) : +xx              eg: +10  
    *                relative in seconds (2) : x <  946681200   eg: 10  
    *                absolute unixtime       : x < 2147483648   eg: 2147483648  
    *                see comments in code for details  
    * @return integer unix timestamp  
        //for api-compatibility, one has not to provide a "+",  
        // if integer is < 946681200 (= Jan 01 2000 00:00:00)  
        if ($expires[0 ] ==  '+' ||  $expires < 946681200 ) {  
            return(time() +  $expires);   
        } elseif  ($expires < 100000000000 ) {  
            //if integer is < 100000000000 (= in 3140 years),  
            // it must be an absolut unixtime  
            // (since the "human readable" definition asks for a higher number)  
            // else it's "human readable";  
            $year =  substr($expires, 0 , 4 );   
            $month =  substr($expires, 4 , 2 );   
            $day =  substr($expires, 6 , 2 );   
            $hour =  substr($expires, 8 , 2 );   
            $minute =  substr($expires, 10 , 2 );   
            $second =  substr($expires, 12 , 2 );   
            return mktime($hour, $minute, $second, $month, $day, $year);   
    } // end func getExpireAbsolute  
 
 
        
		    
 
		    Documentation generated on Mon, 11 Mar 2019 15:25:49 -0400 by  phpDocumentor 1.4.4. PEAR Logo Copyright ©  PHP Group 2004.
	        
       |