Solar_Cache_Adapter::save()

public bool Solar_Cache_Adapter::save ( string $key , string $data , int $life = NULL )

Updates cache entry data, inserting if it does not already exist.

Parameters

  • (string) $key: The entry ID.

  • (string) $data: The data to store.

  • (int) $life: A custom lifespan, in seconds, for the entry; if null, uses the default lifespan for the adapter instance.

Returns

  • (bool) True on success, false on failure.

Description

Updates cache entry data, inserting if it does not already exist.

This method stores data to the cache with its own entry identifier. If the entry does not exist, it is created; if the entry does already exist, it is updated with the new data.

Does not replace if caching is not active.

For example, to store an array in the cache ...

<?php
// create a cache object
$cache = Solar::factory('Solar_Cache');

// create a unique ID
$id = 'my_array';

// set up some data to cache (this could be string output, or
// an object, or almost anything else)
$data = array('foo' => 'bar', 'baz' => 'dib', 'zim' => 'gir');

// store to the cache, overwriting any previous $id entry
$cache->save($id, $data);

// now fetch back the data for the $id entry
$result = $cache->fetch($id);

// $data and $result should be identical


Local