Jarves\Cache\Cacher::setFastCache PHP Метод

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

Does not use cache invalidation mechanism. Notes: Not practical for load balances or php-pm scenarios. Not even practical when you use PHP in PHP-FPM, because there are several php instances as well which do nothing know about cache refreshing in this fast cache. Is only useful for configuration purposes at bootstrap or in combination with the invalidation mechanism (which is then the same as if you would call setDistributedCache())
public setFastCache ( string $key, mixed $value, integer $lifeTime = null ) : boolean
$key string
$value mixed Only simple data types. Serialize your value if you have objects/arrays.
$lifeTime integer
Результат boolean
    public function setFastCache($key, $value, $lifeTime = null)
    {
        return $this->fastCache->set($key, $value, $lifeTime);
    }

Usage Example

Пример #1
0
 /**
  * @param string $lang
  * @param bool $force
  * @return array|null|string
  *
  * @throws \Jarves\Exceptions\BundleNotFoundException
  */
 public function loadMessages($lang = 'en', $force = false)
 {
     if (!$this->isValidLanguage($lang)) {
         $lang = 'en';
     }
     if ($this->messages && isset($this->messages['__lang']) && $this->messages['__lang'] == $lang && $force == false) {
         return null;
     }
     if (!$lang) {
         return null;
     }
     $code = 'core/lang/' . $lang;
     $this->messages = $this->cacher->getFastCache($code);
     $md5 = '';
     $bundles = array();
     foreach ($this->jarves->getBundles() as $bundleName => $bundle) {
         $path = $bundle->getPath();
         if ($path) {
             $path .= "/Resources/translations/{$lang}.po";
             if (file_exists($path)) {
                 $md5 .= @filemtime($path);
                 $bundles[] = $bundleName;
             }
         }
     }
     $md5 = md5($md5);
     if (!$this->messages || count($this->messages) == 0 || !isset($this->messages['__md5']) || $this->messages['__md5'] != $md5) {
         $this->messages = array('__md5' => $md5, '__plural' => $this->getPluralForm($lang), '__lang' => $lang);
         foreach ($bundles as $key) {
             $file = $this->jarves->resolvePath("@{$key}/{$lang}.po", 'Resources/translations');
             $po = $this->getLanguage($file);
             $this->messages = array_merge($this->messages, $po['translations']);
         }
         $this->cacher->setFastCache($code, $this->messages);
     }
     include_once $this->getPluralPhpFunctionFile($lang);
     return $this->messages;
 }
All Usage Examples Of Jarves\Cache\Cacher::setFastCache