The FilesCache.php file is a concrete implementation of the abstract Cache class in the PHPFast framework. It provides methods to store, retrieve, and manage cached data using the file system. Below is a detailed explanation of each method along with examples of how to use them.
connect()
Connect to the file-based cache system by setting up the cache directory.
Sets the cache directory to the configured path or the system's temporary directory if not specified.
Creates the cache directory if it does not exist.
This method is called automatically when an instance of RedisCache is created.
set()
functionset($key,$value,$ttl=3600)
Stores a value in the cache with a specified expiration time (Time-To-Live).
$key – The key under which to store the value.
$value – The value to store.
$ttl – Time-to-live in seconds.
$ttl - true if the value was successfully set, false otherwise
Example:
get()
Retrieves a value from the cache using its unique key.
$key – The key of the value to retrieve.
return – The value stored in the cache or null if not found
Example:
delete()
Removes a specific cached value from the system.
$key – The key of the value to delete.
return – true if the value was successfully deleted, false otherwise.
Example:
has()
Checks whether a specific key exists in the cache.
$key – The key to check for existence.
return – true if key exists, false otherwise.
Example:
clear()
Removes all cached entries, effectively resetting the cache storage.
return – true if the cache was successfully cleared, false otherwise
Example:
Summary
The RedisCache.php file extends the abstract Cache class to provide Redis-based caching functionality. It includes methods to connect to the Redis server, store and retrieve cached data, delete cached data, check for the existence of cached data, and clear all cached data. This implementation allows developers to use Redis as a caching mechanism in their PHPFast applications.