Cache
extends Getters
in package
The GravCache object is used throughout Grav to store and retrieve cached data.
It uses DoctrineCache library and supports a variety of caching mechanisms. Those include:
APCu RedisCache MemCache MemCacheD FileSystem
Table of Contents
Properties
- $all_remove : mixed
- $assets_remove : mixed
- $cache_dir : string
- $cache_remove : mixed
- $config : Config
- $driver : CacheProvider
- $driver_name : string
- $driver_setting : string
- $enabled : bool
- $gettersVariable : string
- $images_remove : mixed
- $key : string
- $lifetime : int
- $now : int
- $simpleCache : CacheInterface
- $standard_remove : mixed
- $standard_remove_no_images : mixed
- $tmp_remove : mixed
Methods
- __construct() : mixed
- Constructor
- __get() : mixed
- Magic getter method
- __isset() : bool
- Magic method to determine if the attribute is set
- __set() : mixed
- Magic setter method
- __unset() : mixed
- Magic method to unset the attribute
- clearCache() : array<string|int, mixed>
- Helper method to clear all Grav caches
- clearJob() : void
- Static function to call as a scheduled Job to clear Grav cache
- contains() : bool
- Returns a boolean state of whether or not the item exists in the cache based on id key
- count() : int
- delete() : bool
- Deletes an item in the cache based on the id
- deleteAll() : bool
- Deletes all cache
- fetch() : mixed|bool
- Gets a cached entry if it exists based on an id. If it does not exist, it returns false
- getCacheDriver() : CacheProvider
- Automatically picks the cache mechanism to use. If you pick one manually it will use that If there is no config option for $driver in the config, or it's set to 'auto', it will pick the best option based on which cache extensions are installed.
- getCacheStatus() : string
- Get cache state
- getDriverName() : string
- Returns the current driver name
- getDriverSetting() : string
- Returns the current driver setting
- getEnabled() : bool
- Returns the current enabled state
- getKey() : string
- Getter method to get the cache key
- getLifetime() : int
- Retrieve the cache lifetime (in seconds)
- getSimpleCache() : CacheInterface
- init() : void
- Initialization that sets a base key and the driver based on configuration settings
- invalidateCache() : void
- isVolatileDriver() : bool
- is this driver a volatile driver in that it resides in PHP process memory
- offsetExists() : bool
- offsetGet() : mixed
- offsetSet() : mixed
- offsetUnset() : mixed
- onSchedulerInitialized() : void
- purgeJob() : string|void
- Static function to call as a scheduled Job to purge old Doctrine files
- purgeOldCache() : int
- Deletes old cache files based on age
- save() : mixed
- Stores a new cached entry.
- setEnabled() : void
- Public accessor to set the enabled state of the cache
- setKey() : void
- Setter method to set key (Advanced)
- setLifetime() : void
- Set the cache lifetime programmatically
- toArray() : array<string|int, mixed>
- Returns an associative array of object properties.
Properties
$all_remove
protected
static mixed
$all_remove
= ['cache://', 'cache://images', 'asset://', 'tmp://']
$assets_remove
protected
static mixed
$assets_remove
= ['asset://']
$cache_dir
protected
string
$cache_dir
$cache_remove
protected
static mixed
$cache_remove
= ['cache://']
$config
protected
Config
$config
$driver
protected
CacheProvider
$driver
$driver_name
protected
string
$driver_name
$driver_setting
protected
string
$driver_setting
$enabled
protected
bool
$enabled
$gettersVariable
protected
string
$gettersVariable
= null
Define variable used in getters.
$images_remove
protected
static mixed
$images_remove
= ['cache://images']
$key
protected
string
$key
Cache key.
$lifetime
protected
int
$lifetime
$now
protected
int
$now
$simpleCache
protected
CacheInterface
$simpleCache
$standard_remove
protected
static mixed
$standard_remove
= ['cache://twig/', 'cache://doctrine/', 'cache://compiled/', 'cache://clockwork/', 'cache://validated-', 'cache://images', 'asset://']
$standard_remove_no_images
protected
static mixed
$standard_remove_no_images
= ['cache://twig/', 'cache://doctrine/', 'cache://compiled/', 'cache://clockwork/', 'cache://validated-', 'asset://']
$tmp_remove
protected
static mixed
$tmp_remove
= ['tmp://']
Methods
__construct()
Constructor
public
__construct(Grav $grav) : mixed
Parameters
- $grav : Grav
__get()
Magic getter method
public
__get(int|string $offset) : mixed
Parameters
- $offset : int|string
-
Medium name value
Attributes
- #[ReturnTypeWillChange]
Return values
mixed —Medium value
__isset()
Magic method to determine if the attribute is set
public
__isset(int|string $offset) : bool
Parameters
- $offset : int|string
-
Medium name value
Attributes
- #[ReturnTypeWillChange]
Return values
bool —True if the value is set
__set()
Magic setter method
public
__set(int|string $offset, mixed $value) : mixed
Parameters
- $offset : int|string
-
Medium name value
- $value : mixed
-
Medium value
Attributes
- #[ReturnTypeWillChange]
__unset()
Magic method to unset the attribute
public
__unset(int|string $offset) : mixed
Parameters
- $offset : int|string
-
The name value to unset
Attributes
- #[ReturnTypeWillChange]
clearCache()
Helper method to clear all Grav caches
public
static clearCache([string $remove = 'standard' ]) : array<string|int, mixed>
Parameters
- $remove : string = 'standard'
-
standard|all|assets-only|images-only|cache-only
Return values
array<string|int, mixed>clearJob()
Static function to call as a scheduled Job to clear Grav cache
public
static clearJob(string $type) : void
Parameters
- $type : string
contains()
Returns a boolean state of whether or not the item exists in the cache based on id key
public
contains(string $id) : bool
Parameters
- $id : string
-
the id of the cached data entry
Return values
bool —true if the cached items exists
count()
public
count() : int
Attributes
- #[ReturnTypeWillChange]
Return values
intdelete()
Deletes an item in the cache based on the id
public
delete(string $id) : bool
Parameters
- $id : string
-
the id of the cached data entry
Return values
bool —true if the item was deleted successfully
deleteAll()
Deletes all cache
public
deleteAll() : bool
Return values
boolfetch()
Gets a cached entry if it exists based on an id. If it does not exist, it returns false
public
fetch(string $id) : mixed|bool
Parameters
- $id : string
-
the id of the cached entry
Return values
mixed|bool —returns the cached entry, can be any type, or false if doesn't exist
getCacheDriver()
Automatically picks the cache mechanism to use. If you pick one manually it will use that If there is no config option for $driver in the config, or it's set to 'auto', it will pick the best option based on which cache extensions are installed.
public
getCacheDriver() : CacheProvider
Return values
CacheProvider —The cache driver to use
getCacheStatus()
Get cache state
public
getCacheStatus() : string
Return values
stringgetDriverName()
Returns the current driver name
public
getDriverName() : string
Return values
stringgetDriverSetting()
Returns the current driver setting
public
getDriverSetting() : string
Return values
stringgetEnabled()
Returns the current enabled state
public
getEnabled() : bool
Return values
boolgetKey()
Getter method to get the cache key
public
getKey() : string
Return values
stringgetLifetime()
Retrieve the cache lifetime (in seconds)
public
getLifetime() : int
Return values
intgetSimpleCache()
public
getSimpleCache() : CacheInterface
Return values
CacheInterfaceinit()
Initialization that sets a base key and the driver based on configuration settings
public
init(Grav $grav) : void
Parameters
- $grav : Grav
invalidateCache()
public
static invalidateCache() : void
isVolatileDriver()
is this driver a volatile driver in that it resides in PHP process memory
public
isVolatileDriver(string $setting) : bool
Parameters
- $setting : string
Return values
booloffsetExists()
public
offsetExists(int|string $offset) : bool
Parameters
- $offset : int|string
Attributes
- #[ReturnTypeWillChange]
Return values
booloffsetGet()
public
offsetGet(int|string $offset) : mixed
Parameters
- $offset : int|string
Attributes
- #[ReturnTypeWillChange]
offsetSet()
public
offsetSet(int|string $offset, mixed $value) : mixed
Parameters
- $offset : int|string
- $value : mixed
Attributes
- #[ReturnTypeWillChange]
offsetUnset()
public
offsetUnset(int|string $offset) : mixed
Parameters
- $offset : int|string
Attributes
- #[ReturnTypeWillChange]
onSchedulerInitialized()
public
onSchedulerInitialized(Event $event) : void
Parameters
- $event : Event
purgeJob()
Static function to call as a scheduled Job to purge old Doctrine files
public
static purgeJob([bool $echo = false ]) : string|void
Parameters
- $echo : bool = false
Return values
string|voidpurgeOldCache()
Deletes old cache files based on age
public
purgeOldCache() : int
Return values
intsave()
Stores a new cached entry.
public
save(string $id, array<string|int, mixed>|object|int $data[, int|null $lifetime = null ]) : mixed
Parameters
- $id : string
-
the id of the cached entry
- $data : array<string|int, mixed>|object|int
-
the data for the cached entry to store
- $lifetime : int|null = null
-
the lifetime to store the entry in seconds
setEnabled()
Public accessor to set the enabled state of the cache
public
setEnabled(bool|int $enabled) : void
Parameters
- $enabled : bool|int
setKey()
Setter method to set key (Advanced)
public
setKey(string $key) : void
Parameters
- $key : string
setLifetime()
Set the cache lifetime programmatically
public
setLifetime(int $future) : void
Parameters
- $future : int
-
timestamp
toArray()
Returns an associative array of object properties.
public
toArray() : array<string|int, mixed>