class PhpFrontend extends StringFrontend (View source)

A cache frontend tailored to PHP code.

Properties

protected string $identifier

Identifies this cache

from  AbstractFrontend
protected PhpCapableBackendInterface $backend

Methods

__construct(string $identifier, BackendInterface $backend)

Constructs the cache

void
initializeObject()

Initializes this frontend

string
getIdentifier()

Returns this cache's identifier

getBackend()

Returns the backend used by this cache

bool
has(string $entryIdentifier)

Checks if a cache entry with the specified identifier exists.

bool
remove(string $entryIdentifier)

Removes the given cache entry from the cache.

void
flush()

Removes all cache entries of this cache.

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.

void
collectGarbage()

Does garbage collection

bool
isValidEntryIdentifier(string $identifier)

Checks the validity of an entry identifier. Returns true if it's valid.

bool
isValidTag(string $tag)

Checks the validity of a tag. Returns true if it's valid.

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

Saves the PHP source code in the cache.

mixed
get(string $entryIdentifier)

Finds and returns the original code from the cache.

array
getByTag(string $tag)

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

string
getWrapped(string $entryIdentifier)

Returns the code wrapped in php tags as written to the cache, ready to be included.

mixed
requireOnce(string $entryIdentifier)

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

Details

__construct(string $identifier, BackendInterface $backend)

Constructs the cache

Parameters

string $identifier

A identifier which describes this cache

BackendInterface $backend

Backend to be used for this cache

void initializeObject()

Initializes this frontend

The backend is connected with this frontend in initializeObject(), not in __construct(), because the Cache Factory needs an opportunity to register the cache before the backend's setCache() method is called. See CacheFactory::create() for details. A backend (for example the SimpleFileBackend) may rely on the cache already being registered at the CacheManager when its setCache() method is called.

Return Value

void

string getIdentifier()

Returns this cache's identifier

Return Value

string

The identifier for this cache

BackendInterface getBackend()

Returns the backend used by this cache

Return Value

BackendInterface

The backend used by this cache

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 the given cache entry from the cache.

Parameters

string $entryIdentifier

An identifier specifying the cache entry

Return Value

bool

true if such an entry exists, false if not

Exceptions

InvalidArgumentException

void flush()

Removes all cache entries of this cache.

Return Value

void

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

Exceptions

InvalidArgumentException

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

Exceptions

InvalidArgumentException

void collectGarbage()

Does garbage collection

Return Value

void

bool isValidEntryIdentifier(string $identifier)

Checks the validity of an entry identifier. Returns true if it's valid.

Parameters

string $identifier

An identifier to be checked for validity

Return Value

bool

bool isValidTag(string $tag)

Checks the validity of a tag. Returns true if it's valid.

Parameters

string $tag

A tag to be checked for validity

Return Value

bool

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

Saves the PHP source code in the cache.

Parameters

string $entryIdentifier

Something which identifies the data - depends on concrete cache

string $sourceCode

PHP source code

array $tags

Tags to associate with this cache entry

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

InvalidDataException
InvalidArgumentException
Exception

mixed get(string $entryIdentifier)

Finds and returns the original code from the cache.

Parameters

string $entryIdentifier

Something which identifies the cache entry - depends on concrete cache

Return Value

mixed

The value or false if the cache entry could not be loaded

Exceptions

InvalidArgumentException

array getByTag(string $tag)

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

Parameters

string $tag

The tag to search for

Return Value

array

An array with the identifier (key) and content (value) of all matching entries. An empty array if no entries matched

Exceptions

NotSupportedByBackendException
InvalidArgumentException

string getWrapped(string $entryIdentifier)

Returns the code wrapped in php tags as written to the cache, ready to be included.

Parameters

string $entryIdentifier

Return Value

string

Exceptions

InvalidArgumentException

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