FileBackend extends SimpleFileBackend implements FreezableBackendInterface, TaggableBackendInterface

A caching backend which stores cache entries in files

Table of Contents

Interfaces

FreezableBackendInterface
A contract for a cache backend which can be frozen.
TaggableBackendInterface
A contract for a cache backend which supports tagging.

Constants

DATASIZE_DIGITS  = 10
DATETIME_EXPIRYTIME_UNLIMITED  = '9999-12-31T23:59:59+0000'
EXPIRYTIME_FORMAT  = 'YmdHis'
EXPIRYTIME_LENGTH  = 14
SEPARATOR  = '^'
UNLIMITED_LIFETIME  = 0

Properties

$cache  : FrontendInterface
Reference to the cache which uses this backend
$cacheDirectory  : string
Directory where the files are stored
$cacheEntryFileExtension  : string
A file extension to use for each cache entry.
$cacheEntryIdentifiers  : array<string|int, mixed>
$cacheIdentifier  : string
$context  : string
The current application context
$defaultLifetime  : int
Default lifetime of a cache entry in seconds
$frozen  : bool
$temporaryCacheDirectory  : string
Temporary path to cache directory before setCache() was called. It is set by setCacheDirectory() and used in setCache() method which calls the directory creation if needed. The variable is not used afterwards, the final cache directory path is stored in $this->cacheDirectory then.

Methods

__construct()  : mixed
Constructs this backend
collectGarbage()  : mixed
Does garbage collection
findIdentifiersByTag()  : array<string|int, mixed>
Finds and returns all cache entry identifiers which are tagged by the specified tag.
flush()  : mixed
Removes all cache entries of this cache and sets the frozen flag to FALSE.
flushByTag()  : mixed
Removes all cache entries of this cache which are tagged by the specified tag.
flushByTags()  : mixed
Backwards compatibility safeguard since re-introducing flushByTags as API.
freeze()  : mixed
Freezes this cache backend.
get()  : mixed
Loads data from a cache file.
getCacheDirectory()  : string
Returns the directory where the cache files are stored
has()  : bool
Checks if a cache entry with the specified identifier exists.
isFrozen()  : bool
Tells if this backend is frozen.
remove()  : bool
Removes all cache entries matching the specified identifier.
require()  : mixed
Loads PHP code from the cache and require it right away.
requireOnce()  : mixed
Loads PHP code from the cache and require_onces it right away.
set()  : mixed
Saves data in a cache file.
setCache()  : mixed
Sets a reference to the cache frontend which uses this backend and initializes the default cache directory.
setCacheDirectory()  : mixed
Sets the directory where the cache files are stored. By default it is assumed that the directory is below TYPO3's Project Path. However, an absolute path can be selected, too.
setDefaultLifetime()  : mixed
Sets the default lifetime for this cache backend
calculateExpiryTime()  : DateTime
Calculates the expiry time by the given lifetime. If no lifetime is specified, the default lifetime is used.
createFinalCacheDirectory()  : mixed
Create the final cache directory if it does not exist.
findCacheFilesByIdentifier()  : mixed
Tries to find the cache entry for the specified identifier.
isCacheFileExpired()  : bool
Checks if the given cache entry files are still valid or if their lifetime has exceeded.

Constants

DATASIZE_DIGITS

public mixed DATASIZE_DIGITS = 10

DATETIME_EXPIRYTIME_UNLIMITED

public mixed DATETIME_EXPIRYTIME_UNLIMITED = '9999-12-31T23:59:59+0000'

EXPIRYTIME_FORMAT

public mixed EXPIRYTIME_FORMAT = 'YmdHis'

EXPIRYTIME_LENGTH

public mixed EXPIRYTIME_LENGTH = 14

UNLIMITED_LIFETIME

public mixed UNLIMITED_LIFETIME = 0

Properties

$cacheDirectory

Directory where the files are stored

protected string $cacheDirectory = ''

$cacheEntryFileExtension

A file extension to use for each cache entry.

protected string $cacheEntryFileExtension = ''

$cacheEntryIdentifiers

protected array<string|int, mixed> $cacheEntryIdentifiers = []

$cacheIdentifier

protected string $cacheIdentifier

$context

The current application context

protected string $context

This variable is currently unused and set to "production" always. It is only kept to keep backwards compatibility.

$defaultLifetime

Default lifetime of a cache entry in seconds

protected int $defaultLifetime = 3600

$temporaryCacheDirectory

Temporary path to cache directory before setCache() was called. It is set by setCacheDirectory() and used in setCache() method which calls the directory creation if needed. The variable is not used afterwards, the final cache directory path is stored in $this->cacheDirectory then.

protected string $temporaryCacheDirectory = ''

Temporary path to cache directory

Methods

__construct()

Constructs this backend

public __construct(string $context[, array<string|int, mixed> $options = [] ]) : mixed
Parameters
$context : string

Unused, for backward compatibility only

$options : array<string|int, mixed> = []

Configuration options - depends on the actual backend

Tags
throws
InvalidArgumentException

collectGarbage()

Does garbage collection

public collectGarbage() : mixed

findIdentifiersByTag()

Finds and returns all cache entry identifiers which are tagged by the specified tag.

public findIdentifiersByTag(string $searchedTag) : array<string|int, mixed>
Parameters
$searchedTag : string

The tag to search for

Return values
array<string|int, mixed>

An array with identifiers of all matching entries. An empty array if no entries matched

flush()

Removes all cache entries of this cache and sets the frozen flag to FALSE.

public flush() : mixed

flushByTag()

Removes all cache entries of this cache which are tagged by the specified tag.

public flushByTag(string $tag) : mixed
Parameters
$tag : string

The tag the entries must have

flushByTags()

Backwards compatibility safeguard since re-introducing flushByTags as API.

public flushByTags(array<string|int, string> $tags) : mixed

See https://review.typo3.org/#/c/50537/ comments for patch set 14.

The method is here even though it is only required for TaggableBackendInterface. We add it here to ensure third party cache backends do not fail but instead delegate to a less efficient linear flushing behavior.

Parameters
$tags : array<string|int, string>

freeze()

Freezes this cache backend.

public freeze() : mixed

All data in a frozen backend remains unchanged and methods which try to add or modify data result in an exception thrown. Possible expiry times of individual cache entries are ignored.

On the positive side, a frozen cache backend is much faster on read access. A frozen backend can only be thawed by calling the flush() method.

Tags
throws
RuntimeException

get()

Loads data from a cache file.

public get(string $entryIdentifier) : mixed
Parameters
$entryIdentifier : string

An identifier which describes the cache entry to load

Tags
throws
InvalidArgumentException

If identifier is invalid

Return values
mixed

The cache entry's content as a string or FALSE if the cache entry could not be loaded

getCacheDirectory()

Returns the directory where the cache files are stored

public getCacheDirectory() : string
Return values
string

Full path of the cache directory

has()

Checks if a cache entry with the specified identifier exists.

public has(string $entryIdentifier) : bool
Parameters
$entryIdentifier : string
Tags
throws
InvalidArgumentException
Return values
bool

TRUE if such an entry exists, FALSE if not

isFrozen()

Tells if this backend is frozen.

public isFrozen() : bool
Return values
bool

remove()

Removes all cache entries matching the specified identifier.

public remove(string $entryIdentifier) : bool

Usually this only affects one entry.

Parameters
$entryIdentifier : string

Specifies the cache entry to remove

Tags
throws
RuntimeException
throws
InvalidArgumentException
Return values
bool

TRUE if (at least) an entry could be removed or FALSE if no entry was found

require()

Loads PHP code from the cache and require it right away.

public require(string $entryIdentifier) : mixed
Parameters
$entryIdentifier : string

An identifier which describes the cache entry to load

Tags
throws
InvalidArgumentException
Return values
mixed

Potential return value from the include operation

requireOnce()

Loads PHP code from the cache and require_onces it right away.

public requireOnce(string $entryIdentifier) : mixed
Parameters
$entryIdentifier : string

An identifier which describes the cache entry to load

Tags
throws
InvalidArgumentException
Return values
mixed

Potential return value from the include operation

set()

Saves data in a cache file.

public set(string $entryIdentifier, string $data[, array<string|int, mixed> $tags = [] ][, int $lifetime = null ]) : mixed
Parameters
$entryIdentifier : string

An identifier for this specific cache entry

$data : string

The data to be stored

$tags : array<string|int, mixed> = []

Tags to associate with this cache entry

$lifetime : int = null

Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited lifetime.

Tags
throws
RuntimeException
throws
InvalidDataException

if the directory does not exist or is not writable or exceeds the maximum allowed path length, or if no cache frontend has been set.

throws
Exception

if the directory does not exist or is not writable or exceeds the maximum allowed path length, or if no cache frontend has been set.

throws
InvalidArgumentException

setCache()

Sets a reference to the cache frontend which uses this backend and initializes the default cache directory.

public setCache(FrontendInterface $cache) : mixed

This method also detects if this backend is frozen and sets the internal flag accordingly.

Parameters
$cache : FrontendInterface

The cache frontend

setCacheDirectory()

Sets the directory where the cache files are stored. By default it is assumed that the directory is below TYPO3's Project Path. However, an absolute path can be selected, too.

public setCacheDirectory(string $cacheDirectory) : mixed

This method enables to use a cache path outside of TYPO3's Project Path. The final cache path is checked and created in createFinalCacheDirectory(), called by setCache() method, which is done after the cacheDirectory option was handled.

Parameters
$cacheDirectory : string

The cache base directory. If a relative path

Tags
throws
Exception

if the directory is not within allowed

setDefaultLifetime()

Sets the default lifetime for this cache backend

public setDefaultLifetime(int $defaultLifetime) : mixed
Parameters
$defaultLifetime : int

Default lifetime of this cache backend in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited lifetime.

Tags
throws
InvalidArgumentException

calculateExpiryTime()

Calculates the expiry time by the given lifetime. If no lifetime is specified, the default lifetime is used.

protected calculateExpiryTime([int $lifetime = null ]) : DateTime
Parameters
$lifetime : int = null

The lifetime in seconds

Return values
DateTime

The expiry time

createFinalCacheDirectory()

Create the final cache directory if it does not exist.

protected createFinalCacheDirectory(string $finalCacheDirectory) : mixed
Parameters
$finalCacheDirectory : string

Absolute path to final cache directory

Tags
throws
Exception

If directory is not writable after creation

findCacheFilesByIdentifier()

Tries to find the cache entry for the specified identifier.

protected findCacheFilesByIdentifier(string $entryIdentifier) : mixed

Usually only one cache entry should be found - if more than one exist, this is due to some error or crash.

Parameters
$entryIdentifier : string

The cache entry identifier

Return values
mixed

The filenames (including path) as an array if one or more entries could be found, otherwise FALSE

isCacheFileExpired()

Checks if the given cache entry files are still valid or if their lifetime has exceeded.

protected isCacheFileExpired(string $cacheEntryPathAndFilename) : bool
Parameters
$cacheEntryPathAndFilename : string
Return values
bool

        
On this page

Search results