FileSystemCache
in package
implements
Cache
The file system cache class
Uses File System to cache data. This class is useful for dated data. This class requires a CACHE_PATH constant containing the path to the cache folder, you can also override getFolderPath() to determine the path by another way.
Table of Contents
Interfaces
- Cache
- The interface to use to define a cache class.
Constants
- VERSION = 1
Properties
- $class : string
- The class of the cache
- $delim : string
- The delimiter in cache file
- $editTime : int|null
- The edit time to use
- $ext : string
- The extension of cache files
- $information : array<string|int, mixed>|null
- $name : string
- The name of the cache
- $path : string
- The path to the cache
Methods
- __construct() : mixed
- Constructor
- clear() : bool
- Clear the cache This method uses unlink() function.
- clearAll() : bool
- Clear all
- get() : bool
- Get the cache for the given parameters This method serializes the data in the file using json_encode().
- getClass() : string
- Class of the cache
- getClassPath() : string
- Get the folder path for the cache
- getEditTime() : int|null
- getFilePath() : string
- Get the fle path of this cache
- getHits() : null
- Get hit count.
- getInformation() : array<string|int, mixed>
- getName() : string
- Name of the cache's class
- getPath() : string
- getSize() : int
- Get size in bytes. 0 if none.
- list() : array<string|int, static>
- List all Filesystem Caches
- set() : bool
- Set the cache for the given parameters This method un-serializes the data in the file using json_decode().
- setInformation() : static
Constants
VERSION
public
mixed
VERSION
= 1
Properties
$class
The class of the cache
protected
string
$class
$delim
The delimiter in cache file
protected
static string
$delim
= '|'
$editTime
The edit time to use
protected
int|null
$editTime
= null
$ext
The extension of cache files
protected
static string
$ext
= '.cache'
$information
protected
array<string|int, mixed>|null
$information
= null
$name
The name of the cache
protected
string
$name
$path
The path to the cache
protected
string
$path
Methods
__construct()
Constructor
public
__construct(string $class, string $name[, int|null $editTime = null ]) : mixed
Parameters
- $class : string
-
The class of the cache
- $name : string
-
The name of this cache
- $editTime : int|null = null
-
The last modification time of the cache. Default value is 0 (undefined).
Tags
clear()
Clear the cache This method uses unlink() function.
public
clear() : bool
Return values
bool —True in case of success
clearAll()
Clear all
public
static clearAll() : bool
Tags
Return values
boolget()
Get the cache for the given parameters This method serializes the data in the file using json_encode().
public
get(mixed &$cached) : bool
The type is preserved, even for objects.
Parameters
- $cached : mixed
-
The output to get the cache
Return values
bool —True if cache has been retrieved
getClass()
Class of the cache
public
getClass() : string
Return values
stringgetClassPath()
Get the folder path for the cache
public
static getClassPath(string $class) : string
Parameters
- $class : string
-
The class to use
Return values
string —The path of this cache folder in the global cache folder.
getEditTime()
public
getEditTime() : int|null
Return values
int|nullgetFilePath()
Get the fle path of this cache
public
static getFilePath(string $class, string $name) : string
Parameters
- $class : string
-
The class to use
- $name : string
-
The name to use
Return values
string —The path of this cache file.
getHits()
Get hit count.
public
getHits() : null
Null if not supported
Return values
nullgetInformation()
public
getInformation() : array<string|int, mixed>
Return values
array<string|int, mixed>getName()
Name of the cache's class
public
getName() : string
Return values
stringgetPath()
public
getPath() : string
Return values
stringgetSize()
Get size in bytes. 0 if none.
public
getSize() : int
Return values
intlist()
List all Filesystem Caches
public
static list() : array<string|int, static>
Tags
Return values
array<string|int, static>set()
Set the cache for the given parameters This method un-serializes the data in the file using json_decode().
public
set(mixed $data) : bool
The type is saved too.
Parameters
- $data : mixed
-
The data to put in the cache
Tags
Return values
bool —True if cache has been saved
setInformation()
protected
setInformation(array<string|int, mixed> $information) : static
Parameters
- $information : array<string|int, mixed>