This is a simple PHP file-based caching system with support for cache monitoring and encryption. It allows you to securely cache data and monitor cache usage in your PHP applications.
- File-based caching: Data is stored in files on the filesystem.
- Cache monitoring: Track cache hits, misses, and cache size.
- Encryption support: Encrypt cached data for security.
- Customizable expiry: Set expiry time for cached data.
- Clone the repository or download the
Cache.phpfile. - Include the
Cache.phpfile in your PHP project.
// Include the Cache class require_once "Cache.php"; // Create a new Cache instance with cache directory and encryption key $cache = new Cache("./cache", "my_secret_key");
// Cache data with optional expiry time (default: no expiry) $cache->set("key", "value", 3600); // Cache "value" with key "key" for 1 hour
// Retrieve cached data if ($cachedData = $cache->get("key");) { echo "Cached data: " . $cachedData; // return "value" - if set } else { echo "Data not found in cache."; // You now may execute a call to the Database and then set the cache }
// Clear cache for a specific key $cache->clearCache("key"); // Clear entire cache $cache->clearCache();
// Get cache hits and misses echo "Cache Hits: " . $cache->getCacheHits() . PHP_EOL; echo "Cache Misses: " . $cache->getCacheMisses() . PHP_EOL;
// Get cache size echo "Cache Size: " . $cache->getCacheSize() . " bytes" . PHP_EOL;
Contributions are welcome! Please feel free to submit issues or pull requests.
This project is licensed under the GPL-3.0 license - see the LICENSE file for details.