Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Core\Cache cache()

...

Store data to in the systems cache.

Examples

...

all(string $key)

 

$key

Unique storage key.

 

del(string $key [, int $id = null] )

 

$key

Unique storage key.

$id

If you stored multiple data in a key
you can pass a unique ID to delete a
specific entry. 

storage()->del('foo'Deletes an entry from cache
MethodDescriptionUsageReturns

get(string $key [, int $id = null] )

 


$key

Unique storage cache key.

$id

If you store multiple data in a key
you can pass a unique ID to return a
specific item from that data set.

 

 

Get data from the DB cache based on a unique key
and/or ID. 

Code Block
languagephp
$objectecho = storagecache()->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
auto incremented key created by Core\Storage\Object. 

Code Block
languagephp
$object = storage()->getById(1);
 
echo $object->value;

On success it returns Core\Storage\Object, null on failure.

Returns all data sets based on a unique key.

 

Code Block
$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

the value, false if its not cached.

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  Sets data cache data based on your key.

 

Info
titleNotice

This method will set multiple entries even if the key already exists.
If you only want one entry for a key make sure to check if it exists and use the update method.

If the cache exists, it will overwrite its value.

 

 

Code Block
// Set a string
storagecache using the key "foo" with the value "bar"
cache()->set('foo', 'bar');
 
// SetStore an array storagein cache
cache()->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
Returns the cached value on success, false on failure.

updatedel(string $key, mixed $value)

 


$key

Unique storage cache 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
any existing data in the value. 

Code Block
storage()->update('foo', 'bar');
 On success it returns the updated Core\Storage\Object, false on failure.Deletes a value from storage based on the key.
Code Block
Code Block
cache()->del('foo');
null
purge()Deletes all entries from cache.
Code Block
cache()->purge();
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.

 

PropertyTypeDescription
idintUnique auto incremented storage ID.
keystringCustom key you pass when accessing the storage methods.
valuemixedReturns any values you stored in storage.
orderintOrder ID of a data set in storage.