Redaxscript\Cache::store PHP Метод

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

store to cache
С версии: 3.0.0
public store ( mixed $bundle = null, string $content = null ) : Cache
$bundle mixed key or collection of the bundle
$content string content of the bundle
Результат Cache
    public function store($bundle = null, $content = null)
    {
        $path = $this->getPath($bundle);
        if (!is_dir($this->_directory)) {
            mkdir($this->_directory);
        }
        if ($path && $content) {
            file_put_contents($path, $content);
        }
        return $this;
    }

Usage Example

Пример #1
0
 /**
  * renderTemplate
  *
  * @since 3.0.0
  *
  * @return mixed
  */
 public static function renderTemplate()
 {
     $registry = Registry::getInstance();
     $request = Request::getInstance();
     $language = Language::getInstance();
     /* handle notification */
     if (!is_dir(self::$_configArray['directory']) && !mkdir(self::$_configArray['directory'])) {
         self::setNotification('error', $language->get('directory_not_found') . $language->get('colon') . ' ' . self::$_configArray['directory'] . $language->get('point'));
     }
     /* prevent as needed */
     if ($request->getPost() || $registry->get('noCache')) {
         return false;
     }
     /* cache as needed */
     $cache = new Cache();
     $cache->init(self::$_configArray['directory'], self::$_configArray['extension']);
     $fullRoute = $registry->get('fullRoute');
     /* load from cache */
     if ($cache->validate($fullRoute, self::$_configArray['lifetime'])) {
         $raw = $cache->retrieve($fullRoute);
         $content = preg_replace('/' . self::$_configArray['tokenPlaceholder'] . '/', $registry->get('token'), self::_uncompress($raw));
         return ['header' => function_exists('gzdeflate') ? 'content-encoding: deflate' : null, 'content' => self::_compress($content)];
     } else {
         $raw = Template\Tag::partial('templates/' . $registry->get('template') . '/index.phtml');
         $content = preg_replace('/' . $registry->get('token') . '/', self::$_configArray['tokenPlaceholder'], $raw);
         $cache->store($fullRoute, self::_compress($content));
         return ['content' => $raw];
     }
 }
All Usage Examples Of Redaxscript\Cache::store