/** * Class constructor. * * @param array $options Initial options for the cache adapter: * - cachedir string The cache directory * @param string $context An optional cache context * @param \Psr\Log\LoggerInterface $logger An optional logger * * @throws \BackBee\Cache\Exception\CacheException Occurs if the cache directory doesn't exist, can not * be created or is not writable. */ public function __construct(array $options = array(), $context = null, LoggerInterface $logger = null) { parent::__construct($options, $context, $logger); $this->cachedir = $this->_instance_options['cachedir']; if (null !== $this->getContext()) { $this->cachedir .= DIRECTORY_SEPARATOR . StringUtils::toPath($this->getContext()); } if (true === $this->_instance_options['cacheautogenerate'] && false === is_dir($this->cachedir) && false === @mkdir($this->cachedir, 0755, true)) { throw new CacheException(sprintf('Unable to create the cache directory `%s`.', $this->cachedir)); } if (true === $this->_instance_options['cacheautogenerate'] && false === is_writable($this->cachedir)) { throw new CacheException(sprintf('Unable to write in the cache directory `%s`.', $this->cachedir)); } $this->log('info', sprintf('File cache system initialized with directory set to `%s`.', $this->cachedir)); }
/** * Returns all classcontents classnames * * @return string[] An array that contains all classcontents classnames */ public function getAllClassContentClassnames() { if (null === $this->contentClassnames) { $cacheId = md5('all_classcontents_classnames_' . $this->app->getContext() . '_' . $this->app->getEnvironment()); if (!$this->app->isDebugMode() && false !== ($value = $this->cache->load($cacheId))) { $this->contentClassnames = json_decode($value, true); } else { $this->contentClassnames = [AbstractClassContent::CLASSCONTENT_BASE_NAMESPACE . 'ContentSet']; foreach ($this->app->getClassContentDir() as $directory) { $this->contentClassnames = array_merge($this->contentClassnames, CategoryManager::getClassContentClassnamesFromDir($directory)); } $this->cache->save($cacheId, json_encode($this->contentClassnames)); } } return $this->contentClassnames; }
/** * {@inheritDoc} */ public function evictClassMetadataFromCache(\ReflectionClass $class) { $cacheId = md5(self::CACHE_PREFIX . $class->name); $this->cache->remove($cacheId); }