/** * @test * @expectedException \Neos\Cache\Exception */ public function setCacheThrowsExceptionOnNonWritableDirectory() { $mockEnvironmentConfiguration = $this->getMockBuilder(EnvironmentConfiguration::class)->setMethods(null)->setConstructorArgs([__DIR__ . '~Testing', 'vfs://Some/NonExisting/Directory/', 1024])->getMock(); $simpleFileBackend = new SimpleFileBackend($mockEnvironmentConfiguration, []); $simpleFileBackend->setCache($this->mockCacheFrontend); $this->getSimpleFileBackend(); }
/** * Sets a reference to the cache frontend which uses this backend and * initializes the default cache directory. * * This method also detects if this backend is frozen and sets the internal * flag accordingly. * * @param FrontendInterface $cache The cache frontend * @return void * @throws Exception */ public function setCache(FrontendInterface $cache) { parent::setCache($cache); if (is_file($this->cacheDirectory . 'FrozenCache.data')) { $this->frozen = true; $cachePathAndFileName = $this->cacheDirectory . 'FrozenCache.data'; $lock = new Lock($cachePathAndFileName, false); $data = file_get_contents($cachePathAndFileName); $lock->release(); if ($this->useIgBinary === true) { $this->cacheEntryIdentifiers = igbinary_unserialize($data); } else { $this->cacheEntryIdentifiers = unserialize($data); } } }
/** * Removes all cache entries matching the specified identifier. * Usually this only affects one entry. * * @param string $entryIdentifier Specifies the cache entry to remove * @return boolean TRUE if (at least) an entry could be removed or FALSE if no entry was found * @throws \RuntimeException * @throws \InvalidArgumentException * @api */ public function remove($entryIdentifier) { if ($this->frozen === true) { throw new \RuntimeException(sprintf('Cannot remove cache entry because the backend of cache "%s" is frozen.', $this->cacheIdentifier), 1323344193); } return parent::remove($entryIdentifier); }
/** * Constructs this backend * * @param ApplicationContext $context Flow's application context * @param array $options Configuration options - depends on the actual backend */ public function __construct(ApplicationContext $context, array $options = []) { $this->context = $context; $environmentConfiguration = $this->createEnvironmentConfiguration($context); parent::__construct($environmentConfiguration, $options); }