Download the PHP package mrmanchot/simple-cache without Composer
On this page you can find all versions of the php package mrmanchot/simple-cache. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mrmanchot/simple-cache
More information about mrmanchot/simple-cache
Files in mrmanchot/simple-cache
Package simple-cache
Short Description A simple and efficient PHP library for cache management.
License
Informations about the package simple-cache
SimpleCache
SimpleCache is a lightweight and efficient PHP caching library, designed for ease of use and flexibility. Whether you're caching strings, arrays, objects, or booleans, SimpleCache provides a straightforward and intuitive API to speed up your PHP applications. With features like cache expiration, subdirectory organization, and security measures, it's an ideal solution for both small projects and large-scale applications.
Features
- Easy to use
- Supports multiple data types: strings, arrays, objects, and booleans
- Allows setting cache expiration time
- Option to bypass cache
- Sanitizes cache keys for security
- Graceful error handling with warnings instead of exceptions
Installation
Use Composer to install this library:
Usage
Initialization
Basic Usage
Using Expiration Time
You can specify an expiration time in minutes using the $delayMinutes
parameter.
Storing Arrays, Objects, and Booleans
You can also store arrays, objects, and booleans.
Handling Cache Hits and Misses
When retrieving data from the cache, you can distinguish between a cache hit and a cache miss by checking if the returned value is null. If the value is null, it indicates that the data is not present in the cache (a cache miss), and you may need to compute or generate the value. If the value is not null, it is a cache hit, and you can use the cached value directly.
Here's an example of how to handle cache hits and misses:
Using Subdirectories as Keys
You can use subdirectories in keys for better organization. Note that keys are sanitized for security purposes, so only certain characters are allowed.
Clearing the Cache
The clear
method allows you to remove cached items based on a pattern. This is useful for batch invalidation of cache items.