Prado\I18N\core\TCache_Lite::get PHP Метод

get() публичный Метод

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
Результат string data of the cache (or false if no cache available)
    function get($id, $group = 'default', $doNotTestCacheValidity = false)
    {
        $this->_id = $id;
        $this->_group = $group;
        $data = false;
        if ($this->_caching) {
            $this->_setFileName($id, $group);
            if ($this->_memoryCaching) {
                if (isset($this->_memoryCachingArray[$this->_file])) {
                    if ($this->_automaticSerialization) {
                        return unserialize($this->_memoryCachingArray[$this->_file]);
                    } else {
                        return $this->_memoryCachingArray[$this->_file];
                    }
                } else {
                    if ($this->_onlyMemoryCaching) {
                        return false;
                    }
                }
            }
            if ($doNotTestCacheValidity) {
                if (file_exists($this->_file)) {
                    $data = $this->_read();
                }
            } else {
                if (@filemtime($this->_file) > $this->_refreshTime) {
                    $data = $this->_read();
                }
            }
            if ($data and $this->_memoryCaching) {
                $this->_memoryCacheAdd($this->_file, $data);
            }
            if ($this->_automaticSerialization && is_string($data)) {
                $data = unserialize($data);
            }
            return $data;
        }
        return false;
    }

Usage Example

Пример #1
0
 /**
  * Get the data from the cache.
  * @param string $catalogue The translation section.
  * @param string $culture The translation locale, e.g. "en_AU".
  * @param string $filename If the source is a file, this file's modified
  * time is newer than the cache's modified time, no cache hit.
  * @return mixed Boolean FALSE if no cache hit. Otherwise, translation
  * table data for the specified section and locale.
  */
 public function get($catalogue, $culture, $lastmodified = 0)
 {
     $ID = $this->getID($catalogue, $culture);
     $group = $this->getGroup($catalogue, $culture);
     $this->cache->_setFileName($ID, $group);
     $cache = $this->cache->getCacheFile();
     if (is_file($cache) == false) {
         return false;
     }
     $lastmodified = (int) $lastmodified;
     if ($lastmodified <= 0 || $lastmodified > filemtime($cache)) {
         return false;
     }
     //echo '@@ Cache hit: "'.$ID.'" : "'.$group.'"';
     //echo "<br>\n";
     return $this->cache->get($ID, $group);
 }