class SimpleFileBackend extends AbstractBackend implements PhpCapableBackendInterface, IterableBackendInterface, WithSetupInterface, WithStatusInterface (View source)

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

Constants

DATETIME_EXPIRYTIME_UNLIMITED

UNLIMITED_LIFETIME

SEPARATOR

EXPIRYTIME_FORMAT

EXPIRYTIME_LENGTH

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.

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.

protected DirectoryIterator|null $cacheFilesIterator
protected string $baseDirectory

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

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.

bool
isCacheFileExpired(string $cacheEntryPathAndFilename)

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

void
collectGarbage()

Not necessary

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

bool|string
readCacheFile(string $cacheEntryPathAndFilename, int $offset = null, 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

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.

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

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

InvalidArgumentException

void flush()

Removes all cache entries of this cache.

Return Value

void

Exceptions

FilesException

protected bool isCacheFileExpired(string $cacheEntryPathAndFilename)

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

Parameters

string $cacheEntryPathAndFilename

Return Value

bool

void collectGarbage()

Not necessary

Return Value

void

protected mixed findCacheFilesByIdentifier(string $entryIdentifier)

Tries to find the cache entry for the specified identifier.

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 include_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 bool|string readCacheFile(string $cacheEntryPathAndFilename, int $offset = null, int $maxlen = null)

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

Parameters

string $cacheEntryPathAndFilename
int $offset
int $maxlen

Return Value

bool|string

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