Пример #1
0
 public function testExistsAndKeys()
 {
     $cacheKey = 'test.exists';
     $exists = Cache::exists($cacheKey);
     $this->assertFalse($exists);
     Cache::set($cacheKey, 'foo');
     $exists = Cache::exists($cacheKey);
     $this->assertTrue($exists);
     // Bug in version < 3.0.2: query keys with prefix in file cache
     if ($_SERVER['PHWOOLCON_PHALCON_VERSION'] >= 3000200) {
         $keys = Cache::queryKeys($cacheKey);
     } else {
         $keys = Cache::queryKeys();
     }
     $this->assertNotEmpty($keys);
 }
Пример #2
0
 public static function all()
 {
     $environment = PhwoolconConfig::environment();
     if (null === ($config = Cache::get($key = 'db_configs_' . $environment))) {
         $db = Db::connection();
         $db->tableExists('config') or static::createConfigTable();
         $config = [];
         /* @var static $row */
         foreach (static::find() as $row) {
             $value = json_decode($row->getData('value'), true);
             $config[$row->getData('key')] = $value;
         }
         Cache::set($key, $config, Cache::TTL_ONE_MONTH);
     }
     return $config;
 }
Пример #3
0
 public static function getSitesData()
 {
     if (null === static::$_sites && null === (static::$_sites = Cache::get($cacheKey = 'sso.sites'))) {
         /* @var static $site */
         $data = [];
         foreach (static::find() as $site) {
             if (!($url = $site->getData('site_url')) || !($host = parse_url($url, PHP_URL_HOST))) {
                 continue;
             }
             $site->setData('host', $host);
             $data[$host] = $site->getData();
         }
         static::$_sites = $data;
         Cache::set($cacheKey, $data);
     }
     return static::$_sites;
 }
Пример #4
0
 public function setBrowserCache($pageId = null, $type = null, $ttl = Cache::TTL_ONE_WEEK)
 {
     $pageId or $pageId = $this->request->getURI();
     $cacheKey = md5($pageId);
     $content = $this->response->getContent();
     $eTag = $this->getContentEtag($content);
     switch ($type) {
         case static::BROWSER_CACHE_ETAG:
             Cache::set('fpc-etag-' . $cacheKey, $eTag, $ttl);
             break;
         case static::BROWSER_CACHE_CONTENT:
             Cache::set('fpc-content-' . $cacheKey, $content, $ttl);
             break;
         default:
             Cache::set('fpc-etag-' . $cacheKey, $eTag, $ttl);
             Cache::set('fpc-content-' . $cacheKey, $content, $ttl);
             break;
     }
     $this->setBrowserCacheHeaders($eTag, $ttl);
     return $this;
 }
Пример #5
0
 /**
  * Writes the meta-data to files
  *
  * @param string $key
  * @param array  $data
  */
 public function write($key, $data)
 {
     $this->_cachedData[$key] = $data;
     Cache::set('model-metadata', $this->_cachedData, Cache::TTL_ONE_MONTH);
 }
Пример #6
0
 public static function assets($collectionName)
 {
     static::$instance or static::$instance = static::$di->getShared('view');
     $view = static::$instance;
     $useCache = $view->config['options']['assets_options']['cache_assets'];
     if (!$view->assets) {
         $view->assets = static::$di->getShared('assets');
         $useCache and static::$cachedAssets = Cache::get('assets');
     }
     $type = substr($collectionName, strrpos($collectionName, '-') + 1);
     $view->isAdmin() and $collectionName = 'admin-' . $collectionName;
     if ($useCache && isset(static::$cachedAssets[$collectionName])) {
         return static::$cachedAssets[$collectionName];
     }
     $view->loadAssets($view->config['assets']);
     $view->loadAssets($view->config['admin']['assets'], true);
     ob_start();
     try {
         switch ($type) {
             case 'js':
                 $view->assets->outputJs($collectionName);
                 break;
             case 'css':
                 $view->assets->outputCss($collectionName);
                 break;
         }
     } catch (Exception $e) {
         Log::exception($e);
     }
     // @codeCoverageIgnoreEnd
     $assets = ob_get_clean();
     static::$cachedAssets[$collectionName] = $assets;
     $useCache and Cache::set('assets', static::$cachedAssets);
     return $assets;
 }
Пример #7
0
 /**
  * @param User  $user
  * @param array $credential
  * @return $this
  */
 public function pushPendingConfirmation($user, array $credential)
 {
     $user->setData('login', $login = $credential['login'])->setData('confirm_class', get_called_class());
     $data = $user->getData();
     Session::set('pending-confirm', $key = md5($login));
     Cache::set('reg-pc-' . $key, $data, $this->options['register']['confirmation_code_ttl']);
     return $this;
 }
Пример #8
0
 public function loadLocale($locale, $force = false)
 {
     if (isset($this->locale[$locale]) && !$force) {
         return $this;
     }
     $useCache = $this->options['cache_locale'];
     $cacheKey = 'locale.' . $locale;
     if ($useCache && !$force && ($cached = Cache::get($cacheKey))) {
         $this->locale[$locale] = $cached;
         return $this;
     }
     $packages = [];
     $combined = [];
     foreach (glob($this->localePath . '/' . $this->currentLocale . '/*.php') as $file) {
         $package = pathinfo($file, PATHINFO_FILENAME);
         $combined = array_merge($combined, $packages[$package] = (array) (include $file));
     }
     $this->locale[$locale] = compact('combined', 'packages');
     $useCache and Cache::set($cacheKey, $this->locale[$locale]);
     return $this;
 }