Description
Core\Cache cache()
Store data to the systems cache.
Examples
// Set a cache using the key "foo" with the value "bar" cache()->set('foo', 'bar'); // Get the value for "foo" echo cache()->get('foo'); // Store an array in cache cache()->set('foo_array', [ 'hello' => 'world' ]); // Get an array from cache $array = cache()->get('foo_array'); print_r($array); // Will output: Array ( [hello] => world ) // Delete an entry from cache cache()->del('foo');
Methods
Method | Description | Usage | Returns |
---|---|---|---|
get(string $key [, int $id = null] )
$key Unique storage key. $id If you store multiple data in a key
| Get data from the DB based on a unique key | $object = storage()->get('foo'); echo $object->value; | On success it returns Core\Storage\Object, null on failure. |
getById(int $id)
$id Unique auto incremented ID. | Get a specific data set based on the unique | $object = storage()->getById(1); echo $object->value; | On success it returns Core\Storage\Object, null on failure. |
all(string $key)
$key Unique storage key.
| Returns all data sets based on a unique key.
| $objects = storage()->all('multiple'); foreach ($objects as $object) { echo $object->value; } | Array of values on success, empty array on failure. Note: Each value from the array is an object from Core\Storage\Object |
set(string $key, mixed $value , int $id = 0] )
$key Unique storage key. $value Value to set for this entry. Can be a string, array, int or boolean. $id (optional) Include a custom unique ID for this data set. | Sets data into the DB based on your key.
Notice This method will set multiple entries even if the key already exists. | // Set a string storage()->set('foo', 'bar'); // Set an array storage()->set('foo_array', [ 'hello' => 'world' ]); // Set multiple values storage()->set('foo', '1'); storage()->set('foo', '2'); storage()->set('foo', '3'); | Returns unique auto increment ID on success, false on failure. |
update(string $key, mixed $value)
$key Unique storage key. $value Value to set for this entry. Can be a string, array, int or boolean.
| Updates the value of a data set that already exists. If the value is an array, it will merge any new data and overwrite | storage()->update('foo', 'bar'); | On success it returns the updated Core\Storage\Object, false on failure. |
del(string $key [, int $id = null] )
$key Unique storage key. $id If you stored multiple data in a key | Deletes a value from storage based on the key. | storage()->del('foo'); | null |
Core\Storage\Object
When we return a data value it returns it as an object. Any value to store can always be accessed via the value property.
Property | Type | Description |
---|---|---|
id | int | Unique auto incremented storage ID. |
key | string | Custom key you pass when accessing the storage methods. |
value | mixed | Returns any values you stored in storage. |
order | int | Order ID of a data set in storage. |