MatthiasMullie\Scrapbook\Scale\StampedeProtector::protect PHP Method

protect() protected method

As soon as a key turns up empty (doesn't yet exist in cache), we'll "protect" it for some time. This will be done by writing to a key similar to the original key name. If this key is present (which it will only be for a short amount of time) we'll know it's protected.
protected protect ( array $keys ) : string[]
$keys array
return string[] Array of keys that were successfully protected
    protected function protect(array $keys)
    {
        if (empty($keys)) {
            return array();
        }
        $success = array();
        foreach ($keys as $key) {
            /*
             * Key is add()ed because there may be multiple concurrent processes
             * that are both in the process of protecting - first one to add()
             * wins (and those are returned by the function, so those that are
             * failed to protect can be considered protected)
             */
            $success[$key] = $this->cache->add($this->stampedeKey($key), '', $this->sla);
        }
        return array_keys(array_filter($success));
    }