Cache
in package
Provides a driver-based interface for finding, creating, and deleting cached resources. Caches are identified by a unique string. Tagging of caches is also supported, and caches can be found and deleted by id or tag.
Table of Contents
Properties
- $config : mixed
- $driver : mixed
- $instances : mixed
- $loaded : mixed
Methods
- __construct() : void
- Loads the configured driver and validates it.
- delete() : bool
- Delete a cache item by id.
- deleteAll() : bool
- Delete ALL cache items items.
- deleteTag() : bool
- Delete all cache items with a given tag.
- find() : array<string|int, mixed>
- Fetches all of the caches for a given tag. An empty array will be returned when no matching caches are found.
- get() : mixed
- Fetches a cache by id. NULL is returned when a cache item is not found.
- instance() : Cache
- Returns a singleton instance of Cache.
- set() : bool
- Set a cache item by id. Tags may also be added and a custom lifetime can be set. Non-string data is automatically serialized.
- sanitizeId() : string
- Replaces troublesome characters with underscores.
Properties
$config
protected
mixed
$config
$driver
protected
mixed
$driver
$instances
protected
static mixed
$instances
= array()
$loaded
protected
static mixed
$loaded
Methods
__construct()
Loads the configured driver and validates it.
public
__construct([array<string|int, mixed>|string|false $config = false ]) : void
Parameters
- $config : array<string|int, mixed>|string|false = false
-
Custom configuration or config group name
delete()
Delete a cache item by id.
public
delete(string $id) : bool
Parameters
- $id : string
-
Cache id
Return values
booldeleteAll()
Delete ALL cache items items.
public
deleteAll() : bool
Return values
booldeleteTag()
Delete all cache items with a given tag.
public
deleteTag(string $tag) : bool
Parameters
- $tag : string
-
Cache tag name
Return values
boolfind()
Fetches all of the caches for a given tag. An empty array will be returned when no matching caches are found.
public
find(string $tag) : array<string|int, mixed>
Parameters
- $tag : string
-
Cache tag
Return values
array<string|int, mixed> —all cache items matching the tag
get()
Fetches a cache by id. NULL is returned when a cache item is not found.
public
get(string $id) : mixed
Parameters
- $id : string
-
Cache id
Return values
mixed —cached data or NULL
instance()
Returns a singleton instance of Cache.
public
static & instance([string|false $config = false ]) : Cache
Parameters
- $config : string|false = false
-
Configuration
Return values
Cacheset()
Set a cache item by id. Tags may also be added and a custom lifetime can be set. Non-string data is automatically serialized.
public
set(string $id, mixed $data[, array<string|int, mixed>|string|null $tags = null ][, int|null $lifetime = null ]) : bool
Parameters
- $id : string
-
Unique cache id
- $data : mixed
-
Data to cache
- $tags : array<string|int, mixed>|string|null = null
-
Tags for this item
- $lifetime : int|null = null
-
Number of seconds until the cache expires
Return values
boolsanitizeId()
Replaces troublesome characters with underscores.
protected
sanitizeId(string $id) : string
Parameters
- $id : string
-
Cache id