Return value is a boolean true when the operation succeeds, or false on
failure.
public set ( string $key, mixed $value, integer $expire ) : boolean | ||
$key | string | |
$value | mixed | |
$expire | integer | Time when item falls out of the cache: 0 = permanent (doesn't expires); under 2592000 (30 days) = relative time, in seconds from now; over 2592000 = absolute time, unix timestamp |
return | boolean |
/** * {@inheritdoc} */ public function set($key, $value, $ttl = null) { if (!is_string($key)) { throw new InvalidArgumentException('Invalid key: ' . serialize($key) . '. Must be string.'); } $ttl = $this->ttl($ttl); return $this->store->set($key, $value, $ttl); }
/** * {@inheritdoc} */ public function save(CacheItemInterface $item) { if (!$item instanceof Item) { throw new InvalidArgumentException('MatthiasMullie\\Scrapbook\\Psr6\\Pool can only save MatthiasMullie\\Scrapbook\\Psr6\\Item objects'); } $expire = $item->getExpiration(); if ($expire !== 0 && $expire < time()) { // already expired: don't even save it return true; } return $this->store->set($item->getKey(), $item->get(), $expire); }
/** * {@inheritdoc} */ public function save(CacheItemInterface $item) { if (!$item instanceof Item) { throw new InvalidArgumentException('MatthiasMullie\\Scrapbook\\Psr6\\Pool can only save MatthiasMullie\\Scrapbook\\Psr6\\Item objects'); } if (!$item->hasChanged()) { /* * If the item didn't change, we don't have to re-save it. We do, * however, need to check if the item actually holds a value: if it * does, it should be considered "saved" (even though nothing has * changed, the value for this key is in cache) and if it doesn't, * well then nothing is in cache. */ return $item->get() !== null; } $expire = $item->getExpiration(); return $this->store->set($item->getKey(), $item->get(), $expire); }
/** * {@inheritdoc} */ public function set($key, $value, $expire = 0) { return $this->cache->set($key, $value, $expire); }