Description
Core\Cache cache()
Store data in 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)
$key Unique cache key.
| Get data from cache based on a key. | echo cache()->get('foo');
| On success it returns the value, false if its not cached. |
set(string $key, mixed $value )
$key Unique storage key. $value Value to set for this entry. Can be a string, array, int or boolean. | Sets data cache data based on your key.
If the cache exists, it will overwrite its value.
| // Set a cache using the key "foo" with the value "bar"
cache()->set('foo', 'bar');
// Store an array in cache
cache()->set('foo_array', [
'hello' => 'world'
]);
| Returns the cached value on success, false on failure. |
del(string $key)
$key Unique cache key. | Deletes an entry from cache | cache()->del('foo');
| null |
| purge() | Deletes all entries from cache. | cache()->purge(); | null |