Download the PHP package slick/cache without Composer
On this page you can find all versions of the php package slick/cache. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package cache
Short Description Cache component for Slick Framework
License MIT
Homepage https://github.com/slickframework/cache
Informations about the package cache
Slick Cache package
Slick cache package works with cache providing services installed on your system.
It comes with support for Memcached (memcached
daemon) and File
(caching data into files) out of the box, but it also defines a driver
interface that allows you to add your own drivers to your project.
Install
Via Composer
Usage
To use a cache driver you simple need to call the Cache::get()
static
method to get an initialized cache driver. Check the following example:
In this example we are using the default cache driver with default options, to store some expensive API call data.
note
The default driver is Memcached with the following default options:
duration => 120
host => ‘127.0.0.1’
port => 11211
Changing cache expire time
The expire amount of time is always set when you set a value on the cache driver. As mention above, the default is set to 120 seconds. Using the above example, we will set the time expire amount to 3 minutes for the data from our fictitious API call:
It is also possible to define a global expire amount of time for all
Cache::set()
like this:
Slick\Cache\DriverInterface::set()
Set/stores a value with a given key. If no value is set in the
expire parameter the default Cache::duration
will be used.
Parameters | Type | Description |
---|---|---|
$key | string | The key where value will be stored |
$value | mixed | The value to store |
$expire | int | The live time of cache in seconds |
Return | Description |
---|---|
Slick\Cache\DriverInterface | A DriverInterface instance for chaining method calls. |
Slick\Cache\DriverInterface::get()
Retrieves a previously stored value. You can optionally set the value returned in case of cache driver has no value for provided key.
Parameters | Type | Description |
---|---|---|
$key | string | The key where value was stored |
$default | mixed | The value returned if cache driver has no value for provided key |
Return | Description |
---|---|
mixed | The stored value or the default value if cache driver has no value for provided key |
Slick\Cache\DriverInterface::erase()
Erase the value stored with a given key. You can use the “?” and “" wildcards to delete all matching keys. The "?" means a place holders for one unknown character, the "” is a place holder for various
Parameters | Type | Description |
---|---|---|
$key | string | The key where value was stored |
Return | Description |
---|---|
Slick\Cache\DriverInterface | A DriverInterface instance for chaining method calls. |
warning
The use of “?” and “*” placeholder is only implemented in the drivers that are provided by Slick cache component. If you create your own cache driver you need to handle the placeholders key search implementation.
tip
If you are implementing your own cache driver and want to have the “?” and “*” placeholders search you can extend
Slick\Cache\Driver\AbstractDriver
witch uses theDriverInterface::get()
andDriverInterface::set()
methods to achieve the wildcards key search feature.
Testing
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.