Download the PHP package webfiori/cache without Composer
On this page you can find all versions of the php package webfiori/cache. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download webfiori/cache
More information about webfiori/cache
Files in webfiori/cache
Package cache
Short Description A simple caching engine which is highly customizable.
License MIT
Informations about the package cache
Cache
A simple caching engine which is highly customizable. This library can be used to implement caching at 3 areas, application, server and database. The cached items are Time-Based, meaning that each item will have a Time-to-Live. Once passed, item will be considered as expired.
Content
- Installation
- Supported PHP Versions
- Usage
- Creating Cache Item
- Retrieving Items
- Retrieve Only
- Retrieve or Create
- Other Operations
- Determining Item Existence
- Removing an Item
- Flush the Cache
- Enabling or Disabling Cache
- Set Custom Cache Store
- License
Installation
If you are using composer to manage your dependencies, then it is possible to install the library by including the entry "webfiori/cache":"*"
in the require
section of your composer.json
file to install the latest release.
Another way to include the library is by going to releases and download the latest release and extract compressed file content and add them to your include directory.
Supported PHP Versions
Build Status |
---|
Usage
The normal workflow of using the library is as follows:
- Cache items are created.
- Cache items are accessed from cache as needed.
- Cached items are re-validated with every access.
- If expired, items are removed from the cache or re-created.
Creating Cache Item
Creating cache entries is performed using the method Cache::set($key, $data)
. The method accepts two mandatory parameters, first one is the key of cache item and second argument is the data that will be cached. Data can be of any type.
This would create a cache entry with duration of 60 seconds. This means if a user tries to access same item after 60 seconds, cache will miss.
To customize time-to-live, a third parameter can be passed which represents the time at which the item will be kept in cache.
To override and revalidate specific cache item, a fourth boolean argument can be used to achieve that.
Retrieving Items
There are two approaches to get cache items, one is retrieve only and the second one is retrieve or create.
Retrieve Only
This approach will attempt to search for the item in cache and return it if found. If not found, null is returned.
Retrieve or Create
This approach is recommended as it will initially attempt to retrieve the item from the cache. If not found, it will create it using a custom callback.
The callback accepts passing parameters as an array as shown in the next sample.
Other Operations
Determining Item Existence
Removing an Item
Flush the Cache
Enabling or Disabling Cache
Enabling cache.
Disabling cache.
Set Custom Cache Store
Developer can create his own custom cache store. To achieve this, the interface webfiori\cache\Store
must be implemented.
License
This library is licensed under MIT license.