FileBackend
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 array | $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
Constructs this backend
No description
Sets a reference to the cache frontend which uses this backend and initializes the default cache directory.
Sets the default lifetime for this cache backend
Calculates the expiry time by the given lifetime. If no lifetime is specified, the default lifetime is used.
Returns the internally used, prefixed entry identifier for the given public entry identifier.
Sets the directory where the cache files are stored
Returns the directory where the cache files are stored
Saves data in a cache file.
Loads data from a cache file.
Checks if a cache entry with the specified identifier exists.
Removes all cache entries matching the specified identifier.
Removes all cache entries of this cache and sets the frozen flag to false.
Checks if the given cache entry files are still valid or if their lifetime has exceeded.
Does garbage collection
Tries to find the cache entry for the specified identifier.
Loads PHP code from the cache and require_onces it right away.
Returns the data of the current cache entry pointed to by the cache entry iterator.
Returns the identifier of the current cache entry pointed to by the cache entry iterator.
Checks if the current position of the cache entry iterator is valid
No description
Reads the cache data from the given cache file, using locking.
Writes the cache data into the given cache file, using locking.
Sets up this backend by creating the required cache directory if it doesn't exist yet
Validates that the configured cache directory exists and is writeable and returns some details about its configuration if that's the case
Freezes this cache backend.
Tells if this backend is frozen.
Finds and returns all cache entry identifiers which are tagged by the specified tag.
Finds and returns all cache entry identifiers which are tagged by the specified tags.
Removes all cache entries of this cache which are tagged by the specified tag.
Removes all cache entries of this cache which are tagged by any of the specified tags.
Internal get method, allows to nest locks by using the $acquireLock flag
Internal get method in case the cache is frozen, this will not check expiry times!
No description
Details
__construct(EnvironmentConfiguration $environmentConfiguration, array $options = [])
Constructs this backend
protected void
setProperties(array $properties, bool $throwExceptionIfPropertyNotSettable = true)
No description
protected 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.
This method also detects if this backend is frozen and sets the internal flag accordingly.
void
setDefaultLifetime(int|string $defaultLifetime)
Sets the default lifetime for this cache backend
protected DateTime
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.
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.
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.
Usually this only affects one entry.
void
flush()
Removes all cache entries of this cache and sets the frozen flag to false.
protected 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
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.
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
protected void
throwExceptionIfPathExceedsMaximumLength(string $cacheEntryPathAndFilename)
No description
string
getBaseDirectory()
No description
void
setBaseDirectory(string $baseDirectory)
No description
protected void
configureCacheDirectory()
No description
protected void
verifyCacheDirectory()
No description
protected string|false
readCacheFile(string $cacheEntryPathAndFilename, int $offset = 0, int $maxlen = null)
Reads the cache data from the given cache file, using locking.
protected bool
writeCacheFile(string $cacheEntryPathAndFilename, string $data)
Writes the cache data into the given cache file, using locking.
Result
setup()
Sets up this backend by creating the required cache directory if it doesn't exist yet
Result
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.
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.
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.
protected bool|string
internalGet(string $entryIdentifier, bool $acquireLock = true)
Internal get method, allows to nest locks by using the $acquireLock flag
protected bool|string
internalGetWhileFrozen(string $entryIdentifier)
Internal get method in case the cache is frozen, this will not check expiry times!
protected string
getEntryIdentifierFromFilename(string $filename)
No description