Cache_Lite::get PHP Method

get() public method

Test if a cache is available and (if yes) return it
public get ( string $id, string $group = 'default', boolean $doNotTestCacheValidity = false ) : string
$id string cache id
$group string name of the cache group
$doNotTestCacheValidity boolean if set to true, the cache validity won't be tested
return string data of the cache (else : false)
    function get($id, $group = 'default', $doNotTestCacheValidity = false)
    {
        $this->_id = $id;
        $this->_group = $group;
        $data = false;
        if ($this->_caching) {
            $this->_setRefreshTime();
            $this->_setFileName($id, $group);
            clearstatcache();
            if ($this->_memoryCaching) {
                if (isset($this->_memoryCachingArray[$this->_file])) {
                    if ($this->_automaticSerialization) {
                        return unserialize($this->_memoryCachingArray[$this->_file]);
                    }
                    return $this->_memoryCachingArray[$this->_file];
                }
                if ($this->_onlyMemoryCaching) {
                    return false;
                }
            }
            if ($doNotTestCacheValidity || is_null($this->_refreshTime)) {
                if (file_exists($this->_file)) {
                    $data = $this->_read();
                }
            } else {
                if (file_exists($this->_file) && @filemtime($this->_file) > $this->_refreshTime) {
                    $data = $this->_read();
                }
            }
            if ($data and $this->_memoryCaching) {
                $this->_memoryCacheAdd($data);
            }
            if ($this->_automaticSerialization and is_string($data)) {
                $data = unserialize($data);
            }
            return $data;
        }
        return false;
    }

Usage Example

コード例 #1
0
 /**
  * Get cached data by ID and group
  *
  * @param   string   $id         The cache data ID
  * @param   string   $group      The cache data group
  * @param   boolean  $checkTime  True to verify cache time expiration threshold
  *
  * @return  mixed  Boolean false on failure or a cached data object
  *
  * @since   11.1
  */
 public function get($id, $group, $checkTime = true)
 {
     static::$CacheLiteInstance->setOption('cacheDir', $this->_root . '/' . $group . '/');
     // This call is needed to ensure $this->rawname is set
     $this->_getCacheId($id, $group);
     return static::$CacheLiteInstance->get($this->rawname, $group);
 }
All Usage Examples Of Cache_Lite::get