63 if ($this->frozen === TRUE) {
64 throw new \RuntimeException(sprintf(
'The cache "%s" is already frozen.', $this->cacheIdentifier), 1323353176);
66 $cacheEntryFileExtensionLength = strlen($this->cacheEntryFileExtension);
67 for ($directoryIterator =
new \DirectoryIterator($this->cacheDirectory); $directoryIterator->valid(); $directoryIterator->next()) {
68 if ($directoryIterator->isDot()) {
71 if ($cacheEntryFileExtensionLength > 0) {
72 $entryIdentifier = substr($directoryIterator->getFilename(), 0, -$cacheEntryFileExtensionLength);
74 $entryIdentifier = $directoryIterator->getFilename();
76 $this->cacheEntryIdentifiers[$entryIdentifier] = TRUE;
77 file_put_contents($this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension, $this->
get($entryIdentifier));
79 if ($this->useIgBinary === TRUE) {
80 file_put_contents($this->cacheDirectory .
'FrozenCache.data', igbinary_serialize($this->cacheEntryIdentifiers));
82 file_put_contents($this->cacheDirectory .
'FrozenCache.data', serialize($this->cacheEntryIdentifiers));
111 parent::setCache($cache);
112 if (file_exists($this->cacheDirectory .
'FrozenCache.data')) {
113 $this->frozen = TRUE;
114 if ($this->useIgBinary === TRUE) {
115 $this->cacheEntryIdentifiers = igbinary_unserialize(file_get_contents($this->cacheDirectory .
'FrozenCache.data'));
117 $this->cacheEntryIdentifiers = unserialize(file_get_contents($this->cacheDirectory .
'FrozenCache.data'));
136 public function set($entryIdentifier, $data, array $tags = array(), $lifetime = NULL) {
137 if (!is_string($data)) {
138 throw new \TYPO3\CMS\Core\Cache\Exception\InvalidDataException(
'The specified data is of type "' . gettype($data) .
'" but a string is expected.', 1204481674);
140 if ($entryIdentifier !== basename($entryIdentifier)) {
141 throw new \InvalidArgumentException(
'The specified entry identifier must not contain a path segment.', 1282073032);
143 if ($entryIdentifier ===
'') {
144 throw new \InvalidArgumentException(
'The specified entry identifier must not be empty.', 1298114280);
146 if ($this->frozen === TRUE) {
147 throw new \RuntimeException(sprintf(
'Cannot add or modify cache entry because the backend of cache "%s" is frozen.', $this->cacheIdentifier), 1323344192);
149 $this->
remove($entryIdentifier);
150 $temporaryCacheEntryPathAndFilename = $this->cacheDirectory . uniqid(
'', TRUE) .
'.temp';
151 $lifetime = $lifetime === NULL ? $this->defaultLifetime : $lifetime;
152 $expiryTime = $lifetime === 0 ? 0 :
$GLOBALS[
'EXEC_TIME'] + $lifetime;
153 $metaData = str_pad($expiryTime, self::EXPIRYTIME_LENGTH) . implode(
' ', $tags) . str_pad(strlen($data), self::DATASIZE_DIGITS);
154 $result = file_put_contents($temporaryCacheEntryPathAndFilename, $data . $metaData);
157 throw new \TYPO3\CMS\Core\Cache\Exception(
'The temporary cache file "' . $temporaryCacheEntryPathAndFilename .
'" could not be written.', 1204026251);
161 while ((
$result = rename($temporaryCacheEntryPathAndFilename, $cacheEntryPathAndFilename)) === FALSE && $i < 5) {
165 throw new \TYPO3\CMS\Core\Cache\Exception(
'The cache file "' . $cacheEntryPathAndFilename .
'" could not be written.', 1222361632);
167 if ($this->cacheEntryFileExtension ===
'.php') {
180 public function get($entryIdentifier) {
181 if ($this->frozen === TRUE) {
182 return isset($this->cacheEntryIdentifiers[$entryIdentifier]) ? file_get_contents($this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension) : FALSE;
184 if ($entryIdentifier !== basename($entryIdentifier)) {
185 throw new \InvalidArgumentException(
'The specified entry identifier must not contain a path segment.', 1282073033);
191 $dataSize = (int)file_get_contents($pathAndFilename, NULL, NULL, (filesize($pathAndFilename) - self::DATASIZE_DIGITS), self::DATASIZE_DIGITS);
192 return file_get_contents($pathAndFilename, NULL, NULL, 0, $dataSize);
203 public function has($entryIdentifier) {
204 if ($this->frozen === TRUE) {
205 return isset($this->cacheEntryIdentifiers[$entryIdentifier]);
207 if ($entryIdentifier !== basename($entryIdentifier)) {
208 throw new \InvalidArgumentException(
'The specified entry identifier must not contain a path segment.', 1282073034);
210 return !$this->
isCacheFileExpired(($this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension));
223 public function remove($entryIdentifier) {
224 if ($entryIdentifier !== basename($entryIdentifier)) {
225 throw new \InvalidArgumentException(
'The specified entry identifier must not contain a path segment.', 1282073035);
227 if ($entryIdentifier ===
'') {
228 throw new \InvalidArgumentException(
'The specified entry identifier must not be empty.', 1298114279);
230 if ($this->frozen === TRUE) {
231 throw new \RuntimeException(sprintf(
'Cannot remove cache entry because the backend of cache "%s" is frozen.', $this->cacheIdentifier), 1323344193);
234 if (file_exists($pathAndFilename) === FALSE) {
237 if (unlink($pathAndFilename) === FALSE) {
252 $entryIdentifiers = array();
254 $cacheEntryFileExtensionLength = strlen($this->cacheEntryFileExtension);
255 for ($directoryIterator = \
TYPO3\CMS\Core\Utility\
GeneralUtility::makeInstance(
'DirectoryIterator', $this->cacheDirectory); $directoryIterator->valid(); $directoryIterator->next()) {
256 if ($directoryIterator->isDot()) {
259 $cacheEntryPathAndFilename = $directoryIterator->getPathname();
260 $index = (int)file_get_contents($cacheEntryPathAndFilename, NULL, NULL, (filesize($cacheEntryPathAndFilename) - self::DATASIZE_DIGITS), self::DATASIZE_DIGITS);
261 $metaData = file_get_contents($cacheEntryPathAndFilename, NULL, NULL, $index);
262 $expiryTime = (int)substr($metaData, 0, self::EXPIRYTIME_LENGTH);
263 if ($expiryTime !== 0 && $expiryTime < $now) {
266 if (in_array($searchedTag, explode(
' ', substr($metaData, self::EXPIRYTIME_LENGTH, -self::DATASIZE_DIGITS)))) {
267 if ($cacheEntryFileExtensionLength > 0) {
268 $entryIdentifiers[] = substr($directoryIterator->getFilename(), 0, -$cacheEntryFileExtensionLength);
270 $entryIdentifiers[] = $directoryIterator->getFilename();
274 return $entryIdentifiers;
285 if ($this->frozen === TRUE) {
286 $this->frozen = FALSE;
299 if (count($identifiers) === 0) {
302 foreach ($identifiers as $entryIdentifier) {
303 $this->
remove($entryIdentifier);
316 if (file_exists($cacheEntryPathAndFilename) === FALSE) {
319 $index = (int)file_get_contents($cacheEntryPathAndFilename, NULL, NULL, (filesize($cacheEntryPathAndFilename) - self::DATASIZE_DIGITS), self::DATASIZE_DIGITS);
320 $expiryTime = (int)file_get_contents($cacheEntryPathAndFilename, NULL, NULL, $index, self::EXPIRYTIME_LENGTH);
321 return $expiryTime !== 0 && $expiryTime <
$GLOBALS[
'EXEC_TIME'];
331 if ($this->frozen === TRUE) {
334 for ($directoryIterator =
new \DirectoryIterator($this->cacheDirectory); $directoryIterator->valid(); $directoryIterator->next()) {
335 if ($directoryIterator->isDot()) {
339 $cacheEntryFileExtensionLength = strlen($this->cacheEntryFileExtension);
340 if ($cacheEntryFileExtensionLength > 0) {
341 $this->
remove(substr($directoryIterator->getFilename(), 0, -$cacheEntryFileExtensionLength));
343 $this->
remove($directoryIterator->getFilename());
358 $pattern = $this->cacheDirectory . $entryIdentifier;
359 $filesFound = glob($pattern);
360 if ($filesFound === FALSE || count($filesFound) === 0) {
375 if ($this->frozen === TRUE) {
376 if (isset($this->cacheEntryIdentifiers[$entryIdentifier])) {
383 if ($entryIdentifier !== basename($entryIdentifier)) {
384 throw new \InvalidArgumentException(
'The specified entry identifier must not contain a path segment.', 1282073036);
387 return $this->
isCacheFileExpired($pathAndFilename) ? FALSE : require_once $pathAndFilename;
isCacheFileExpired($cacheEntryPathAndFilename)
static clearAllActive($fileAbsPath=NULL)
static fixPermissions($path, $recursive=FALSE)
static makeInstance($className)
setCache(\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface $cache)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren't numeric.
findCacheFilesByIdentifier($entryIdentifier)
requireOnce($entryIdentifier)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
findIdentifiersByTag($searchedTag)