CRedisCache
in package
implements
ICache
Class CRedisCache implement the Cache on Redis based on ICache
NOTE: In all code, do NOT use this class, but its extension CCache!
Required to install "predis":
composer require predis/predis
Install redis server: on docker
- docker pull redis
on Debian Linux
- apt install redis-server
- systemctl status redis-server
Set Password: $>redis-cli Redis>config set requirepass pwd123 Redis>auth pwd123 Redis>exit
Tags
Interfaces, Classes, Traits and Enums
- ICache
- Interface 'ICache' for caching data and pages
Table of Contents
- $area_name : string
- $CACHE_PATH : string
- $redis : Client
- $uid : int
- __construct() : mixed
- clear() : void
- Reset all cache
- clearArea() : void
- remove all items of an area
- delete() : void
- Delete a certain key if it exists
- exists() : bool
- Check if a key exists and is in the cache
- existsGlobal() : bool
- Check if a key exists for all user and is in the cache
- get() : mixed
- Get a value of cache by $name and optionally $area_name
- getCacheNames() : array<string|int, string>|bool
- Provides the list of cached file names
- getCachePath() : string
- Returns the path where it writes the cache files
- getGlobal() : mixed
- Get the value of an stored element valid for all users
- getName() : string
- Given the name of a key determines the actual internal key to be used
- set() : void
- Sets the value of an item to be stored
- setArea() : void
- Set the name of current area
- setGlobal() : void
- Sets the value of an item to be stored valid for all user
- setUid() : void
- Set the id of current user
- writeDebug() : void
- Writes a message to a cache-specific log file
Properties
$area_name
private
string
$area_name
Tags
$CACHE_PATH
private
string
$CACHE_PATH
Tags
$redis
private
Client
$redis
Tags
$uid
private
int
$uid
Tags
Methods
__construct()
public
__construct(string $domain[, string $app_name = APP_NAME ][, string $area_name = '' ][, int $uid = 0 ]) : mixed
Parameters
- $domain : string
-
application domain (unique name for each app)
- $app_name : string = APP_NAME
-
name of App (default APP_NAME)
- $area_name : string = ''
-
name of area
- $uid : int = 0
-
the id of current user in table _user (optional)
Tags
Return values
mixed —clear()
Reset all cache
public
clear([ $needle = '' ]) : void
Parameters
Tags
Return values
void —clearArea()
remove all items of an area
public
clearArea([string|null $area_name = null ]) : void
Parameters
- $area_name : string|null = null
-
name of area
Tags
Return values
void —delete()
Delete a certain key if it exists
public
delete(string $key) : void
Parameters
- $key : string
-
name of the key to be deleted
Tags
Return values
void —exists()
Check if a key exists and is in the cache
public
exists(string $name[, string|null $area_name = null ]) : bool
Parameters
- $name : string
-
message to write on file log
- $area_name : string|null = null
-
name of area (null or not declared is the implicit "current area")
Tags
Return values
bool —true if the key $name exists
existsGlobal()
Check if a key exists for all user and is in the cache
public
existsGlobal(string $name[, string|null $area_name = null ]) : bool
Parameters
- $name : string
-
key of the item to be stored
- $area_name : string|null = null
-
name of area (null or not declared is the implicit "current area")
Tags
Return values
bool —true if the key $name exists
get()
Get a value of cache by $name and optionally $area_name
public
get(string $name[, string|null $area_name = null ]) : mixed
Parameters
- $name : string
-
key of the item to be stored
- $area_name : string|null = null
-
name of area (null or not declared is the implicit "current area")
Tags
Return values
mixed —The cached item: it can be a scalar value, an object or an array
getCacheNames()
Provides the list of cached file names
public
getCacheNames() : array<string|int, string>|bool
Tags
Return values
array<string|int, string>|bool —an array with a list of cached file name or false if there are none
getCachePath()
Returns the path where it writes the cache files
public
getCachePath() : string
Tags
Return values
string —the cache path of the application
getGlobal()
Get the value of an stored element valid for all users
public
getGlobal(string $name[, string|null $area_name = null ]) : mixed
Parameters
- $name : string
-
key of the item to be stored
- $area_name : string|null = null
-
name of area (null or not declared is the implicit "current area")
Tags
Return values
mixed —The cached element value: it can be a scalar value, an object or an array
getName()
Given the name of a key determines the actual internal key to be used
public
getName(string $name) : string
Parameters
- $name : string
-
name of key
Tags
Return values
string —the full internal key
set()
Sets the value of an item to be stored
public
set(string $name, mixed $value[, string|null $area_name = null ]) : void
Parameters
- $name : string
-
key of the item to be stored
- $value : mixed
-
value to be stored
- $area_name : string|null = null
-
name of area (null or not declared is the implicit "current area")
Tags
Return values
void —setArea()
Set the name of current area
public
setArea(string $area_name) : void
Parameters
- $area_name : string
-
name of area
Tags
Return values
void —setGlobal()
Sets the value of an item to be stored valid for all user
public
setGlobal(string $name, mixed $value[, string|null $area_name = null ]) : void
Parameters
- $name : string
-
key of the item to be stored
- $value : mixed
-
value to be stored
- $area_name : string|null = null
-
name of area (null or not declared is the implicit "current area")
Tags
Return values
void —setUid()
Set the id of current user
public
setUid(int $uid) : void
Parameters
- $uid : int
-
id of current user (optional)
Tags
Return values
void —writeDebug()
Writes a message to a cache-specific log file
public
writeDebug(mixed $msg) : void
Parameters
- $msg : mixed
-
string message or object to write on file log