/** * Writes item into the cache. * Dependencies are: * - Cache::PRIORITY => (int) priority * - Cache::EXPIRATION => (timestamp) expiration * - Cache::SLIDING => (bool) use sliding expiration? * - Cache::TAGS => (array) tags * - Cache::FILES => (array|string) file names * - Cache::ITEMS => (array|string) cache items * - Cache::CONSTS => (array|string) cache items * * @param mixed key * @param mixed value * @param array dependencies * @return mixed value itself * @throws InvalidArgumentException */ public function save($key, $data, array $dp = NULL) { $this->release(); $key = $this->generateKey($key); if ($data instanceof Callback || $data instanceof Closure) { $this->storage->lock($key); $data = Callback::create($data)->invokeArgs(array(&$dp)); } if ($data === NULL) { $this->storage->remove($key); } else { $this->storage->write($key, $data, $this->completeDependencies($dp, $data)); return $data; } }
/** * Writes item into the cache. * Dependencies are: * - NCache::PRIORITY => (int) priority * - NCache::EXPIRATION => (timestamp) expiration * - NCache::SLIDING => (bool) use sliding expiration? * - NCache::TAGS => (array) tags * - NCache::FILES => (array|string) file names * - NCache::ITEMS => (array|string) cache items * - NCache::CONSTS => (array|string) cache items * * @param mixed key * @param mixed value * @param array dependencies * @return mixed value itself * @throws InvalidArgumentException */ public function save($key, $data, array $dp = NULL) { $this->release(); $key = $this->namespace . md5(is_scalar($key) ? $key : serialize($key)); if ($data instanceof NCallback || $data instanceof Closure) { $this->storage->lock($key); $data = callback($data)->invokeArgs(array(&$dp)); } if ($data === NULL) { $this->storage->remove($key); } else { $this->storage->write($key, $data, $this->completeDependencies($dp, $data)); return $data; } }