Jarves\Cache\Backend\AbstractCache::set PHP Method

set() public method

If you want to save php class objects, you should serialize it before.
public set ( string $key, mixed $value, integer $lifeTime = 3600, boolean $withoutValidationData = false ) : boolean
$key string
$value mixed Do not pass objects, use serialize if you want to store php objects
$lifeTime integer In seconds. Default is one hour
$withoutValidationData boolean
return boolean
    public function set($key, $value, $lifeTime = 3600, $withoutValidationData = false)
    {
        if (!$key) {
            return false;
        }
        if (!$lifeTime) {
            $lifeTime = 3600;
        }
        $this->cache[$key] = $value;
        $result = $this->doSet($key, json_encode($value), $lifeTime);
        return $result;
    }

Usage Example

Example #1
0
 /**
  * Sets a distributed cache.
  *
  * This stores a ms timestamp on the distributed cache (Jarves::setCache())
  * and the actual data on the high-speed cache driver (Jarves::setFastCache()).
  * This mechanism makes sure, you gain the maximum performance by using the
  * fast cache driver to store the actual data and using the distributed cache driver
  * to store a ms timestamp where we can check (over several jarves.cms installations)
  * whether the cache is still valid or not.
  *
  * Use Jarves::invalidateCache($key) to invalidate this cache.
  * You don't have to define the full key, instead you can pass only a part of the key.
  *
  * @see invalidateCache for more information.
  *
  * Don't mix the usage of getDistributedCache() and getCache() since this method
  * stores extra values at the value, which makes getCache() returning something invalid.
  *
  * @param string $key
  * @param mixed $value Only simple data types. Serialize your value if you have objects/arrays.
  * @param int $lifeTime
  *
  * @return boolean
  * @static
  */
 public function setDistributedCache($key, $value, $lifeTime = null)
 {
     $timestamp = microtime(true);
     $cache['data'] = $value;
     $cache['timestamp'] = $timestamp;
     $this->distributedCache->deleteInvalidate($key);
     return $this->fastCache->set($key, $cache, $lifeTime);
 }