class Cache implements CacheInterface

Cache

Constants

DEFAULT_DRIVER

FILESYSTEM_DRIVER

APCU_DRIVER

ARRAY_DRIVER

VOID_DRIVER

MEMCACHED_DRIVER

Properties

protected array $drivers Drivers list
protected Cache $driver Cache driver
protected string $cacheDir Cache directory
protected string $routeCacheFile Route cache file
protected int $saveTime Default save time

Methods

__construct(string $cacheDir, string|null $routerCacheFile, string|null $driverName = null, bool $status = false, int $saveTime = 7)

Constructor

array
getSupportedDrivers()

Get supported driver names.

bool
isAvailable(string $driverName)

Return true if driver name is avaliable

Cache|null
createDriver(string|null $name)

Create cache driver

string
getCacheDir()

Get cache dir

void
setStatus(bool $status)

Set status true - enabled

bool
getStatus()

Get status

bool
isDiabled()

Return true if cache is disabled

Cache
getDriver()

Return cache driver

string|null
getDriverName()

Get cache driver name

void
setDriver(Cache|string $driver)

Set cache driver

mixed|false
fetch(string $id)

Read item

bool
has(string $id)

Check if cache contains item

bool
save(string $id, mixed $data, int $lifeTime = null)

Save cache item

bool
delete(string $id)

Delete cache item

array|null
getStats()

Return cache stats

bool
clear()

Delete all cache items + views cache files and route cache

bool
hasRouteCache()

Return true if route ceche file exist

bool
clearRouteCache()

Delete route cache items and route cache file

Details

at line 94
__construct(string $cacheDir, string|null $routerCacheFile, string|null $driverName = null, bool $status = false, int $saveTime = 7)

Constructor

Parameters

string $cacheDir
string|null $routerCacheFile
string|null $driverName
bool $status
int $saveTime

at line 114
array getSupportedDrivers()

Get supported driver names.

Return Value

array

at line 132
bool isAvailable(string $driverName)

Return true if driver name is avaliable

Parameters

string $driverName

Return Value

bool

at line 153
Cache|null createDriver(string|null $name)

Create cache driver

Parameters

string|null $name

Return Value

Cache|null

Exceptions

Exception

at line 186
string getCacheDir()

Get cache dir

Return Value

string

at line 197
void setStatus(bool $status)

Set status true - enabled

Parameters

bool $status

Return Value

void

at line 207
bool getStatus()

Get status

Return Value

bool

at line 217
bool isDiabled()

Return true if cache is disabled

Return Value

bool

at line 227
Cache getDriver()

Return cache driver

Return Value

Cache

at line 237
string|null getDriverName()

Get cache driver name

Return Value

string|null

at line 253
void setDriver(Cache|string $driver)

Set cache driver

Parameters

Cache|string $driver

Return Value

void

Exceptions

Exception

at line 272
mixed|false fetch(string $id)

Read item

Parameters

string $id

Return Value

mixed|false The cached data or false

at line 283
bool has(string $id)

Check if cache contains item

Parameters

string $id

Return Value

bool

at line 296
bool save(string $id, mixed $data, int $lifeTime = null)

Save cache item

Parameters

string $id The cache id.
mixed $data The cache entry/data.
int $lifeTime In minutes

Return Value

bool true if data was successfully stored in the cache, false otherwise.

at line 309
bool delete(string $id)

Delete cache item

Parameters

string $id cache id.

Return Value

bool

at line 327
array|null getStats()

Return cache stats

Return Value

array|null

at line 337
bool clear()

Delete all cache items + views cache files and route cache

Return Value

bool

at line 350
bool hasRouteCache()

Return true if route ceche file exist

Return Value

bool

at line 360
bool clearRouteCache()

Delete route cache items and route cache file

Return Value

bool