/**
  * Constructs the cache
  *
  * @param string $identifier A identifier which describes this cache
  * @param \TYPO3\Flow\Cache\Backend\BackendInterface $backend Backend to be used for this cache
  * @throws \InvalidArgumentException if the identifier doesn't match PATTERN_ENTRYIDENTIFIER
  */
 public function __construct($identifier, \TYPO3\Fluid\Cache\Backend\BackendInterface $backend)
 {
     if (preg_match(self::PATTERN_ENTRYIDENTIFIER, $identifier) !== 1) {
         throw new \InvalidArgumentException('"' . $identifier . '" is not a valid cache identifier.', 1203584729);
     }
     $this->identifier = $identifier;
     $this->backend = $backend;
     $this->backend->setCache($this);
 }
 /**
  * Sets a reference to the cache frontend which uses this backend and
  * initializes the default cache directory.
  *
  * @param \TYPO3\Flow\Cache\Frontend\FrontendInterface $cache The cache frontend
  * @return void
  * @throws \TYPO3\Flow\Cache\Exception
  */
 public function setCache(FrontendInterface $cache)
 {
     parent::setCache($cache);
     $codeOrData = $cache instanceof PhpFrontend ? 'Code' : 'Data';
     $cacheDirectory = $this->cacheDirectory ?: $this->environment->getPathToTemporaryDirectory() . 'Cache/' . $codeOrData . '/' . $this->cacheIdentifier . '/';
     if (!is_writable($cacheDirectory)) {
         try {
             \TYPO3\Flow\Utility\Files::createDirectoryRecursively($cacheDirectory);
         } catch (\TYPO3\Flow\Utility\Exception $exception) {
             throw new \TYPO3\Flow\Cache\Exception('The cache directory "' . $cacheDirectory . '" could not be created.', 1264426237);
         }
     }
     if (!is_dir($cacheDirectory) && !is_link($cacheDirectory)) {
         throw new \TYPO3\Flow\Cache\Exception('The cache directory "' . $cacheDirectory . '" does not exist.', 1203965199);
     }
     if (!is_writable($cacheDirectory)) {
         throw new \TYPO3\Flow\Cache\Exception('The cache directory "' . $cacheDirectory . '" is not writable.', 1203965200);
     }
     $this->cacheDirectory = $cacheDirectory;
     $this->cacheEntryFileExtension = $cache instanceof PhpFrontend ? '.php' : '';
     if (strlen($this->cacheDirectory) + 23 > $this->environment->getMaximumPathLength()) {
         throw new \TYPO3\Flow\Cache\Exception('The length of the temporary cache path "' . $this->cacheDirectory . '" exceeds the maximum path length of ' . ($this->environment->getMaximumPathLength() - 23) . '. Please consider setting the temporaryDirectoryBase option to a shorter path. ', 1248710426);
     }
 }
 /**
  * Sets a reference to the cache frontend which uses this backend and
  * initializes the default cache directory.
  *
  * @param \TYPO3\Flow\Cache\Frontend\FrontendInterface $cache The cache frontend
  * @return void
  * @throws Exception
  */
 public function setCache(FrontendInterface $cache)
 {
     parent::setCache($cache);
     $cacheDirectory = $this->cacheDirectory;
     if ($cacheDirectory == '') {
         $codeOrData = $cache instanceof PhpFrontend ? 'Code' : 'Data';
         $baseDirectory = $this->cacheManager->isCachePersistent($cache->getIdentifier()) ? FLOW_PATH_DATA . 'Persistent/' : $this->environment->getPathToTemporaryDirectory();
         $cacheDirectory = $baseDirectory . 'Cache/' . $codeOrData . '/' . $this->cacheIdentifier . '/';
     }
     if (!is_writable($cacheDirectory)) {
         try {
             \TYPO3\Flow\Utility\Files::createDirectoryRecursively($cacheDirectory);
         } catch (\TYPO3\Flow\Utility\Exception $exception) {
             throw new Exception('The cache directory "' . $cacheDirectory . '" could not be created.', 1264426237);
         }
     }
     if (!is_dir($cacheDirectory) && !is_link($cacheDirectory)) {
         throw new Exception('The cache directory "' . $cacheDirectory . '" does not exist.', 1203965199);
     }
     if (!is_writable($cacheDirectory)) {
         throw new Exception('The cache directory "' . $cacheDirectory . '" is not writable.', 1203965200);
     }
     $this->cacheDirectory = $cacheDirectory;
     $this->cacheEntryFileExtension = $cache instanceof PhpFrontend ? '.php' : '';
 }
 /**
  * Initializes the identifier prefix when setting the cache.
  *
  * @param FrontendInterface $cache
  * @return void
  */
 public function setCache(FrontendInterface $cache)
 {
     parent::setCache($cache);
     $pathHash = substr(md5(FLOW_PATH_ROOT . $this->context . $cache->getIdentifier()), 0, 12);
     $this->identifierPrefix = 'Flow_' . $pathHash . '_';
 }
 /**
  * Initializes this frontend
  *
  * The backend is connected with this frontend in initializeObject(), not in __construct(), because the Cache Factory
  * needs an opportunity to register the cache before the backend's setCache() method is called. See
  * CacheFactory::create() for details. A backend (for example the SimpleFileBackend) may rely on the cache already
  * being registered at the CacheManager when its setCache() method is called.
  *
  * @return void
  */
 public function initializeObject()
 {
     $this->backend->setCache($this);
 }