SimpleFileBackend extends AbstractBackend implements PhpCapableBackendInterface

A caching backend which stores cache entries in files, but does not support or care about expiry times and tags.

Table of Contents

Interfaces

PhpCapableBackendInterface
A contract for a cache backend which is capable of storing, retrieving and including PHP source code.

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
Not necessary
flush()  : mixed
Removes all cache entries of this cache.
flushByTags()  : mixed
Backwards compatibility safeguard since re-introducing flushByTags as API.
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.
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()

Not necessary

public collectGarbage() : mixed

flush()

Removes all cache entries of this cache.

public flush() : mixed

Flushes a directory by first moving to a temporary resource, and then triggering the remove process. This way directories can be flushed faster to prevent race conditions on concurrent processes accessing the same directory.

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>

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

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
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

This cache backend does not support life times

Tags
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
InvalidDataException

if the data to bes stored is not a string.

throws
InvalidArgumentException

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
Parameters
$entryIdentifier : string

The cache entry identifier

Return values
mixed

The file names (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