ICache
in
Interface for caching data and pages.
Defines the contract for all cache implementations within the framework.
Table of Contents
Methods
- Clear() : void
- Clears the cache. Can be filtered by a search string.
- ClearArea() : void
- Removes all items from a specific area.
- Delete() : void
- Deletes a specific item from the cache.
- Exists() : bool
- Checks if an item exists in the cache for the current user.
- ExistsGlobal() : bool
- Checks if a global item (valid for all users) exists in the cache.
- Get() : mixed
- Retrieves the value of a cached item.
- GetCacheNames() : array<string|int, string>|false
- Provides a list of all cache keys within the current scope.
- GetCachePath() : string
- Returns the physical path where cache files are stored.
- GetGlobal() : mixed
- Retrieves the value of a global cached item (valid for all users).
- GetName() : string
- Generates the actual internal key for a given name.
- Set() : void
- Stores an item in the cache for the current user.
- SetArea() : void
- Sets the name of the current area.
- SetGlobal() : void
- Stores a global item in the cache (valid for all users).
- SetUid() : void
- Sets the user ID for the current context.
- WriteDebug() : void
- Writes a message to a cache-specific log file for debugging purposes.
Methods
Clear()
Clears the cache. Can be filtered by a search string.
public
Clear([string $needle = '*' ]) : void
Parameters
- $needle : string = '*'
-
Removes all keys containing this string. If '*' or empty, clears the entire current scope (area/user).
ClearArea()
Removes all items from a specific area.
public
ClearArea(string $area_name) : void
Parameters
- $area_name : string
-
The name of the area to clear.
Delete()
Deletes a specific item from the cache.
public
Delete(string $name) : void
Parameters
- $name : string
-
The key of the item to delete.
Exists()
Checks if an item exists in the cache for the current user.
public
Exists(string $name[, string|null $area_name = null ]) : bool
Parameters
- $name : string
-
The key of the item to check.
- $area_name : string|null = null
-
The area name. If null, the current area is used.
Return values
bool —True if the item exists, false otherwise.
ExistsGlobal()
Checks if a global item (valid for all users) exists in the cache.
public
ExistsGlobal(string $name[, string|null $area_name = null ]) : bool
Parameters
- $name : string
-
The key of the item to check.
- $area_name : string|null = null
-
The area name. If null, the current area is used.
Return values
bool —True if the item exists, false otherwise.
Get()
Retrieves the value of a cached item.
public
Get(string $name[, string|null $area_name = null ]) : mixed
Parameters
- $name : string
-
The key of the item to retrieve.
- $area_name : string|null = null
-
The area name. If null, the current area is used.
Return values
mixed —The cached item's value (can be a scalar, array, or object), or null if not found or on error.
GetCacheNames()
Provides a list of all cache keys within the current scope.
public
GetCacheNames() : array<string|int, string>|false
Return values
array<string|int, string>|false —An array with a list of cache keys, or false if the scope is empty or not accessible.
GetCachePath()
Returns the physical path where cache files are stored.
public
GetCachePath() : string
Note: This may not be applicable to all cache drivers (e.g., Redis).
Return values
string —The cache path of the application. Returns an empty string if not applicable.
GetGlobal()
Retrieves the value of a global cached item (valid for all users).
public
GetGlobal(string $name[, string|null $area_name = null ]) : mixed
Parameters
- $name : string
-
The key of the item to retrieve.
- $area_name : string|null = null
-
The area name. If null, the current area is used.
Return values
mixed —The cached item's value, or null if not found or on error.
GetName()
Generates the actual internal key for a given name.
public
GetName(string $name) : string
The internal key usually includes prefixes for domain, app, area, and user ID.
Parameters
- $name : string
-
The public key of the item.
Return values
string —The complete internal key used by the cache system.
Set()
Stores an item in the cache for the current user.
public
Set(string $name, mixed $value[, string|null $area_name = null ]) : void
Parameters
- $name : string
-
The key of the item to store.
- $value : mixed
-
The value to be stored.
- $area_name : string|null = null
-
The area name. If null, the current area is used.
SetArea()
Sets the name of the current area.
public
SetArea(string $area_name) : void
Areas are used to group related cache items.
Parameters
- $area_name : string
-
The name of the area.
SetGlobal()
Stores a global item in the cache (valid for all users).
public
SetGlobal(string $name, mixed $value[, string|null $area_name = null ]) : void
Parameters
- $name : string
-
The key of the item to store.
- $value : mixed
-
The value to be stored.
- $area_name : string|null = null
-
The area name. If null, the current area is used.
SetUid()
Sets the user ID for the current context.
public
SetUid(int $uid) : void
This allows for user-specific caching.
Parameters
- $uid : int
-
The ID of the current user. A value of 0 typically represents a global (non-user-specific) context.
WriteDebug()
Writes a message to a cache-specific log file for debugging purposes.
public
WriteDebug(mixed $msg) : void
Parameters
- $msg : mixed
-
The string message or object to write to the log file.