This is a simple PHP caching class that allows you to save, retrieve, and delete cache data using files.
- Efficient Storage: Data is stored in a compressed and base64-encoded format.
- Metadata: Each cache item contains metadata such as its creation and last updated time.
- Flexible Directory Structure: If the designated cache directory does not exist, the class will automatically create it.
Ensure that the directory where you want to store cache files has the appropriate write permissions. You should also set a constant or variable named CACHE_LOCATION
with the directory path where cache files should be saved.
-
Include the Cache Class:
include 'CACHE.php';
-
Initialize:
$cache = new CACHE();
-
Save Data to Cache:
$result = $cache->SAVE('my_data_key', array('some' => 'data'));
-
Retrieve Data from Cache:
$data = $cache->GET('my_data_key');
-
Delete Data from Cache:
$result = $cache->DELETE('my_data_key');
The class will return an associative array containing the status of the operation ("OK"
or "ERR"
) and a message describing the outcome. For successful GET
operations, the data will also be included.
Feel free to contribute to this project by submitting pull requests or issues.
This project is open-source and licensed under the MIT License. See the LICENSE file for details.