Create object in the database and set in memcached
@param array $exclude Attributes not to set
@param integer|boolean $cache Number of seconds to cache the object for
0 = cache never expires, FALSE = do not cache
@return boolean
179013
public function create ($exclude = array (), $cache = FALSE)
	{
		
		// If we're not caching or there is no memcached object just call parent
		
		if ($cache === FALSE || !($this->memcached instanceof \Memcached))
		{
			return parent::create ($exclude);
		}
		
		// Call parent method
		
		$parent	= parent::create ($exclude);
		
		if ($parent === FALSE)
		{
			return FALSE;
		}
		
		// Cache
		
		$this->memcached->set ($this->getMemcachedID (), $this->getCacheAttributes (), $cache);
		
		// Return
		
		return $parent;
		
	}
337739
public function setCache(array $data)
    {
        if (!$this->isCached) {
            $this->memcache->set(
                $this->config['key_prefix'] . '.storage',
                $data,
                false,
                $this->config['expiration_time']
            );
        }

        return $this;
    }
782196
public function setCache($cache)
    {
        if ($cache instanceof \Zend_Cache_Core) {
            $this->cache = $cache;
        } elseif ($cache instanceof \Zend_Config) {
            $this->cache = \Zend_Cache::factory($cache->toArray());
        } elseif (is_array($cache)) {
            $this->cache = \Zend_Cache::factory($cache);
        } else {
            throw new \Zend_Session_SaveHandler_Exception('Cache options must be in an associative array or instance of Zend_Config or Zend_Cache_Core.');
        }

        return $this;
    }
959617
public void refreshCache(String cacheName, List<String> excludedFormats) {
        CacheService cache = allCaches.get(cacheName);
        if (cache != null) {
            if (excludedFormats != null && cache instanceof ExcludableCache && excludedFormats.contains(((ExcludableCache)cache).getFormat())) {
                logger.debug(" - omitting cache " + cacheName);
            }
            else {
                logger.info(" - refresh cache " + cacheName);
                try {
                    cache.refreshCache();
                } catch (Exception e) {
                    logger.severeException("failed to refresh cache", e);
                }
            }
        }
    }
386823
public function setCacheDir($cacheDir)
    {
        if ($cacheDir !== null) {
            if (!is_dir($cacheDir)) {
                throw new Exception\InvalidArgumentException(
                    "Cache directory '{$cacheDir}' not found or not a directory"
                );
            } elseif (!is_writable($cacheDir)) {
                throw new Exception\InvalidArgumentException(
                    "Cache directory '{$cacheDir}' not writable"
                );
            } elseif (!is_readable($cacheDir)) {
                throw new Exception\InvalidArgumentException(
                    "Cache directory '{$cacheDir}' not readable"
                );
            }

            $cacheDir = rtrim(realpath($cacheDir), DIRECTORY_SEPARATOR);
        } else {
            $cacheDir = sys_get_temp_dir();
        }

        $this->cacheDir = $cacheDir;

        return $this;
    }
1150082
public function setCache($cache)
    {
        $this->cache = $cache;
        if ($this->isBool($cache) && $cache === false) {
            $this->cache = $cache;
        } else {
            if (is_object($cache)) {
                if ($this->isInstanceOf($cache, CacheStorage::class)) {
                    $this->cache = $cache;
                } else {
                    throw new RouterException('$cache must either be a boolean or instance of ' . CacheStorage::class . '.');
                }
            } else {
                $this->cache = $this->cache($cache);
            }
        }
    }
210646
public static function fromCache($cache)
    {
        if (!is_object($cache)) {
            throw new InvalidArgumentException('Cache must be one of the known cache objects');
        }

        if ($cache instanceof CacheAdapterInterface) {
            return $cache;
        } elseif ($cache instanceof Cache) {
            return new DoctrineCacheAdapter($cache);
        } elseif ($cache instanceof StorageInterface) {
            return new Zf2CacheAdapter($cache);
        } else {
            throw new InvalidArgumentException('Unknown cache type: ' . get_class($cache));
        }
    }
532430
public function setCache(array $data) 
    {

        if (!is_writable(preg_replace('/[\/][^\/]+\.[^\/]++$/', null, 
            $this->path))) {
            throw new Exception('Temp directory ' . 
            htmlspecialchars($this->path, ENT_QUOTES, 'UTF-8') . 
            ' seems not writable');
        }    	
        
        if ((!file_exists($this->path) || (time()-filectime($this->path)) > 
            $this->config['expiration_time'])) {
            $handle = @fopen($this->path, 'w+');
            $serialized = @serialize($data);
            
            if (!$handle) {
                throw new Exception("Cache file couldn't be created");
            }
			if (!$serialized) {
                throw new Exception("Cache data couldn't be serialized");
            }            

            fwrite($handle, $serialized);
            fclose($handle);
        }

        return $this;
    }
410201
public function decode($string, $exclude=null)
    {
        if ( !is_string( $exclude) ) {
            $exclude = ';/?:@&=+$,#';
        }

        $cache = $this->getDecodeCache($exclude);

        return preg_replace_callback("/(%[a-f0-9]{2})+/i", function($seq) use(&$cache) {
            $result = '';
            $seq = $seq[0];
            for ($i = 0, $l = strlen($seq); $i < $l; $i += 3) {
                $b1 = intval(substr($seq, $i + 1, 2), 16);

                if ($b1 < 0x80) {
                    $result .= $cache[$b1];
                    continue;
                }
                $result .= chr($b1);
            }
            return $result;
        },$string);
    }
1014050
public function setNoCache($noCache = true)
    {
        // Affect all non-disabled states
        $applyTo = [self::STATE_ENABLED, self::STATE_PRIVATE, self::STATE_PUBLIC];
        if ($noCache) {
            $this->setStateDirective($applyTo, 'no-cache');
            $this->removeStateDirective($applyTo, 'max-age');
            $this->removeStateDirective($applyTo, 's-maxage');
        } else {
            $this->removeStateDirective($applyTo, 'no-cache');
        }
        return $this;
    }
1068314
public function Create ($exclude = array (), &$db = FALSE)
	{
		
		// Check email is unique
		
		if (!$this->uniqueEmail ())
		{
			
			// Set message
			
			new \Sonic\Message ('error', 'The email address `' . $this->iget ('email') . '` is already assigned to an account! Please choose another.');
			
			// Return FALSE
			
			return FALSE;
			
		}
		
		// Hash password
		
		$password	= $this->iget ('password');
		$this->iset ('password', self::_Hash ($password));
		
		// Call parent method
		
		$parent	= parent::Create ($exclude, $db);
		
		// Reset password
		
		$this->iset ('password', $password);
		
		// Return
		
		return $parent;
		
	}
1266721
public function cache($cache = null)
    {
        if ($cache === null) {
            return $this->_cache;
        }

        if ($cache === false) {
            $this->_cache = false;

            return $this;
        }

        if ($cache === true) {
            $cache = 'cake_pdf';
        }

        if (!in_array($cache, Cache::configured())) {
            throw new Exception(sprintf('CakePdf cache is not configured: %s', $cache));
        }

        $this->_cache = $cache;

        return $this;
    }
504306
public function set_cache_layer($cache) {
        if (!method_exists($cache, 'set') || !method_exists($cache, 'get')) {
            throw new \Exception("Invalid cache layer - must have set and get.");
        }

        $this->_cache = $cache;
    }
1296840
protected function prepareArray(array $collection, array $exclude)
  {
    foreach ($collection as $key => $value)
    {
      if ($this->exclude($key, $exclude) === false)
      {
        $collection[$key] = $this->prepareArrayValue($value, $this->excludeNext($key, $exclude));
      }
      else
      {
        unset($collection[$key]);
      }
    }

    return $collection;
  }
855811
public static function get($key) {
		$memcached = self::connect();
		$var = $memcached->get($key);
		if ($var === false) {
			throw new \Exception('Object not in cache');
		} else {
			return $var;
		}
	}
778900
public function clear($cache = null)
    {
        if (null !== $cache) {
            if (!array_key_exists($cache, $this->caches)) {
                throw new CacheNotFoundException($cache);
            }

            $this->caches[$cache]->clear();
        } else {
            foreach ($this->caches as $cache) {
                $cache->clear();
            }
        }
    }
664810
protected function refreshExpiredCacheForContext($context = null, $forceRefresh = false)
    {
        $key = $this->getKey($context);
        if ($forceRefresh || $this->needRefresh($key)) {
            $this->logger->debug("Refreshing cache for $key ...");
            $this->cacheStorage->setItem($this->statusKeyFor($key), static::PENDING);
            $this->cacheStorage->setItem($key, serialize($this->getDataFromRealService($context)));
            $this->cacheStorage->setItem($this->statusKeyFor($key), static::COMPLETED);
            $this->cacheStorage->setItem($this->refreshedAtKeyFor($key), serialize($this->getDateTimeFactory()->now()));
            $this->logger->debug("Cache for $key has been refreshed !");
            return true;
        }
        return false;
    }