class FileBackend extends SimpleFileBackend implements PhpCapableBackendInterface, FreezableBackendInterface, TaggableBackendInterface (View source)

A caching backend which stores cache entries in files

Constants

DATETIME_EXPIRYTIME_UNLIMITED

UNLIMITED_LIFETIME

SEPARATOR

EXPIRYTIME_FORMAT

deprecated EXPIRYTIME_LENGTH

deprecated DATASIZE_DIGITS

Properties

protected FrontendInterface $cache

Reference to the cache frontend which uses this backend

from  AbstractBackend
protected string $cacheIdentifier from  AbstractBackend
protected string $identifierPrefix

A prefix to seperate stored by appliaction context and cache

from  AbstractBackend
protected int $defaultLifetime

Default lifetime of a cache entry in seconds

from  AbstractBackend
protected EnvironmentConfiguration $environmentConfiguration from  AbstractBackend
protected string $cacheDirectory

Directory where the files are stored.

from  SimpleFileBackend
protected string $cacheEntryFileExtension

A file extension to use for each cache entry.

protected string[] $cacheEntryIdentifiers
protected bool $frozen
protected bool $useIgBinary

If the extension "igbinary" is installed, use it for increased performance.

from  SimpleFileBackend
protected DirectoryIterator|null $cacheFilesIterator from  SimpleFileBackend
protected string $baseDirectory

Overrides the base directory for this cache, the effective directory will be a subdirectory of this.

from  SimpleFileBackend

Methods

__construct(EnvironmentConfiguration $environmentConfiguration, array $options = [])

Constructs this backend

void
setProperties(array $properties, bool $throwExceptionIfPropertyNotSettable = true)

No description

bool
setProperty(string $propertyName, mixed $propertyValue)

No description

void
setCache(FrontendInterface $cache)

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

void
setDefaultLifetime(int|string $defaultLifetime)

Sets the default lifetime for this cache backend

calculateExpiryTime(int $lifetime = null)

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

string
getPrefixedIdentifier(string $entryIdentifier)

Returns the internally used, prefixed entry identifier for the given public entry identifier.

void
setCacheDirectory(string $cacheDirectory)

Sets the directory where the cache files are stored

string
getCacheDirectory()

Returns the directory where the cache files are stored

void
set(string $entryIdentifier, string $data, array $tags = [], int $lifetime = null)

Saves data in a cache file.

mixed
get(string $entryIdentifier)

Loads data from a cache file.

bool
has(string $entryIdentifier)

Checks if a cache entry with the specified identifier exists.

bool
remove(string $entryIdentifier)

Removes all cache entries matching the specified identifier.

void
flush()

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

bool
isCacheFileExpired(string $cacheEntryPathAndFilename, bool $acquireLock = true)

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

void
collectGarbage()

Does garbage collection

mixed
findCacheFilesByIdentifier(string $entryIdentifier)

Tries to find the cache entry for the specified identifier.

mixed
requireOnce(string $entryIdentifier)

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

mixed
current()

Returns the data of the current cache entry pointed to by the cache entry iterator.

void
next()

Move forward to the next cache entry

string
key()

Returns the identifier of the current cache entry pointed to by the cache entry iterator.

bool
valid()

Checks if the current position of the cache entry iterator is valid

void
rewind()

Rewinds the cache entry iterator to the first element

void
throwExceptionIfPathExceedsMaximumLength(string $cacheEntryPathAndFilename)

No description

string
getBaseDirectory()

No description

void
setBaseDirectory(string $baseDirectory)

No description

void
configureCacheDirectory()

No description

void
verifyCacheDirectory()

No description

string|false
readCacheFile(string $cacheEntryPathAndFilename, int $offset = 0, int $maxlen = null)

Reads the cache data from the given cache file, using locking.

bool
writeCacheFile(string $cacheEntryPathAndFilename, string $data)

Writes the cache data into the given cache file, using locking.

setup()

Sets up this backend by creating the required cache directory if it doesn't exist yet

getStatus()

Validates that the configured cache directory exists and is writeable and returns some details about its configuration if that's the case

void
freeze()

Freezes this cache backend.

bool
isFrozen()

Tells if this backend is frozen.

array
findIdentifiersByTag(string $searchedTag)

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

array
findIdentifiersByTags(array $tags)

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

int
flushByTag(string $tag)

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

int
flushByTags(array $tags)

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

bool|string
internalGet(string $entryIdentifier, bool $acquireLock = true)

Internal get method, allows to nest locks by using the $acquireLock flag

bool|string
internalGetWhileFrozen(string $entryIdentifier)

Internal get method in case the cache is frozen, this will not check expiry times!

string
getEntryIdentifierFromFilename(string $filename)

No description

Details

__construct(EnvironmentConfiguration $environmentConfiguration, array $options = [])

Constructs this backend

Parameters

EnvironmentConfiguration $environmentConfiguration
array $options

Configuration options - depends on the actual backend

protected void setProperties(array $properties, bool $throwExceptionIfPropertyNotSettable = true)

No description

Parameters

array $properties
bool $throwExceptionIfPropertyNotSettable

Return Value

void

Exceptions

InvalidArgumentException

protected bool setProperty(string $propertyName, mixed $propertyValue)

No description

Parameters

string $propertyName
mixed $propertyValue

Return Value

bool

void setCache(FrontendInterface $cache)

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.

Parameters

FrontendInterface $cache

The frontend for this backend

Return Value

void

Exceptions

Exception

void setDefaultLifetime(int|string $defaultLifetime)

Sets the default lifetime for this cache backend

Parameters

int|string $defaultLifetime

Default lifetime of this cache backend in seconds. 0 means unlimited lifetime.

Return Value

void

Exceptions

InvalidArgumentException

protected DateTime calculateExpiryTime(int $lifetime = null)

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

Parameters

int $lifetime

The lifetime in seconds

Return Value

DateTime

The expiry time

string getPrefixedIdentifier(string $entryIdentifier)

Returns the internally used, prefixed entry identifier for the given public entry identifier.

While Flow applications will mostly refer to the simple entry identifier, it may be necessary to know the actual identifier used by the cache backend in order to share cache entries with other applications. This method allows for retrieving it.

Note that, in case of the AbstractBackend, this method is returns just the given entry identifier.

Parameters

string $entryIdentifier

Return Value

string

void setCacheDirectory(string $cacheDirectory)

Sets the directory where the cache files are stored

Parameters

string $cacheDirectory

Full path of the cache directory

Return Value

void

string getCacheDirectory()

Returns the directory where the cache files are stored

Return Value

string

Full path of the cache directory

void set(string $entryIdentifier, string $data, array $tags = [], int $lifetime = null)

Saves data in a cache file.

Parameters

string $entryIdentifier

An identifier for this specific cache entry

string $data

The data to be stored

array $tags

Tags to associate with this cache entry. If the backend does not support tags, this option can be ignored.

int $lifetime

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

Return Value

void

Exceptions

RuntimeException
Exception
InvalidArgumentException

mixed get(string $entryIdentifier)

Loads data from a cache file.

Parameters

string $entryIdentifier

An identifier which describes the cache entry to load

Return Value

mixed

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

Exceptions

InvalidArgumentException

bool has(string $entryIdentifier)

Checks if a cache entry with the specified identifier exists.

Parameters

string $entryIdentifier

An identifier specifying the cache entry

Return Value

bool

true if such an entry exists, false if not

Exceptions

InvalidArgumentException

bool remove(string $entryIdentifier)

Removes all cache entries matching the specified identifier.

Usually this only affects one entry.

Parameters

string $entryIdentifier

Specifies the cache entry to remove

Return Value

bool

true if (at least) an entry could be removed or false if no entry was found

Exceptions

RuntimeException
InvalidArgumentException

void flush()

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

Return Value

void

Exceptions

FilesException

protected bool isCacheFileExpired(string $cacheEntryPathAndFilename, bool $acquireLock = true)

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

Parameters

string $cacheEntryPathAndFilename
bool $acquireLock

Return Value

bool

void collectGarbage()

Does garbage collection

Return Value

void

protected mixed findCacheFilesByIdentifier(string $entryIdentifier)

Tries to find the cache entry for the specified identifier.

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

Parameters

string $entryIdentifier

The cache entry identifier

Return Value

mixed

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

mixed requireOnce(string $entryIdentifier)

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

Parameters

string $entryIdentifier

An identifier which describes the cache entry to load

Return Value

mixed

Potential return value from the include operation

Exceptions

InvalidArgumentException

mixed current()

Returns the data of the current cache entry pointed to by the cache entry iterator.

Return Value

mixed

void next()

Move forward to the next cache entry

Return Value

void

string key()

Returns the identifier of the current cache entry pointed to by the cache entry iterator.

Return Value

string

bool valid()

Checks if the current position of the cache entry iterator is valid

Return Value

bool

true if the current position is valid, otherwise false

void rewind()

Rewinds the cache entry iterator to the first element

Return Value

void

protected void throwExceptionIfPathExceedsMaximumLength(string $cacheEntryPathAndFilename)

No description

Parameters

string $cacheEntryPathAndFilename

Return Value

void

Exceptions

Exception

string getBaseDirectory()

No description

Return Value

string

void setBaseDirectory(string $baseDirectory)

No description

Parameters

string $baseDirectory

Return Value

void

protected void configureCacheDirectory()

No description

Return Value

void

Exceptions

Exception

protected void verifyCacheDirectory()

No description

Return Value

void

Exceptions

Exception

protected string|false readCacheFile(string $cacheEntryPathAndFilename, int $offset = 0, int $maxlen = null)

Reads the cache data from the given cache file, using locking.

Parameters

string $cacheEntryPathAndFilename
int $offset
int $maxlen

Return Value

string|false

The contents of the cache file or false on error

protected bool writeCacheFile(string $cacheEntryPathAndFilename, string $data)

Writes the cache data into the given cache file, using locking.

Parameters

string $cacheEntryPathAndFilename
string $data

Return Value

bool

Return value of file_put_contents

Result setup()

Sets up this backend by creating the required cache directory if it doesn't exist yet

Return Value

Result

Result getStatus()

Validates that the configured cache directory exists and is writeable and returns some details about its configuration if that's the case

Return Value

Result

void freeze()

Freezes this cache backend.

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.

Return Value

void

Exceptions

RuntimeException

bool isFrozen()

Tells if this backend is frozen.

Return Value

bool

array findIdentifiersByTag(string $searchedTag)

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

Parameters

string $searchedTag

The tag to search for

Return Value

array

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

array findIdentifiersByTags(array $tags)

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

Parameters

array $tags

The tags to search for

Return Value

array

An array with identifiers of all matching entries. An empty array if no entries matched or no tags were provided

int flushByTag(string $tag)

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

Parameters

string $tag

The tag the entries must have

Return Value

int

The number of entries which have been affected by this flush

int flushByTags(array $tags)

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

Parameters

array $tags

The tags the entries must have

Return Value

int

The number of entries which have been affected by this flush

protected bool|string internalGet(string $entryIdentifier, bool $acquireLock = true)

Internal get method, allows to nest locks by using the $acquireLock flag

Parameters

string $entryIdentifier
bool $acquireLock

Return Value

bool|string

Exceptions

InvalidArgumentException

protected bool|string internalGetWhileFrozen(string $entryIdentifier)

Internal get method in case the cache is frozen, this will not check expiry times!

Parameters

string $entryIdentifier

Return Value

bool|string

Exceptions

InvalidArgumentException

protected string getEntryIdentifierFromFilename(string $filename)

No description

Parameters

string $filename

Return Value

string