Jamm\Memory\MemcacheObject::save PHP Method

save() public method

Save variable in memory storage
public save ( string $key, mixed $value, integer $ttl = 259200, array | string $tags = NULL ) : boolean
$key string - key
$value mixed - value
$ttl integer - time to live (store) in seconds
$tags array | string - array of tags for this key
return boolean
    public function save($key, $value, $ttl = 259200, $tags = NULL)
    {
        $key = (string) $key;
        $ttl = $this->ttl_to_expiration($ttl);
        if (false === $this->memcache->set($this->prefix . $key, $value, 0, $ttl)) {
            $reason = $this->prefix . $key;
            if (strlen($key) > 250) {
                $reason = 'key length should be <250';
            } elseif (strlen(serialize($value)) > 1048576) {
                $reason = 'size of value should be <1Mb';
            }
            $this->ReportError('memcache can not store key: ' . $reason, __LINE__);
            return false;
        }
        $this->setKeyTTL($key, $ttl);
        if (!empty($tags)) {
            $this->setTags($key, $tags);
        }
        return true;
    }