delete() public method

Deletes a value with the specified key from cache
public delete ( mixed $key ) : boolean
$key mixed a key identifying the value to be deleted from cache. This can be a simple string or a complex data structure consisting of factors representing the key.
return boolean if no error happens during deletion
Exemplo n.º 1
0
 /**
  * @inheritdoc
  */
 protected function releaseLock($name)
 {
     if (!$this->cache instanceof Cache) {
         return false;
     }
     return $this->cache->delete($this->getCacheKey($name));
 }
Exemplo n.º 2
0
 /**
  * @param array $assignments
  * $assignments = [
  *  'user_id' => ['role_1', 'role_2', 'role_3'],
  *  '1' => ['admin', 'user'],
  *  '2' => ['client', 'user'],
  *  '3' => ['manager', 'seller', 'support', 'user'],
  * ];
  * @throws \yii\base\InvalidConfigException
  */
 protected function restoreAssignments($assignments)
 {
     $useCache = $this->useCache === true;
     foreach ($assignments as $user_id => $items) {
         if (!empty($this->forceAssign)) {
             if (!is_array($this->forceAssign)) {
                 $this->forceAssign = (array) $this->forceAssign;
             }
             foreach ($this->forceAssign as $role) {
                 $this->authManager->assign(RbacFactory::Role($role), $user_id);
                 echo sprintf('    > role `%s` force assigned to user id: %s.', $role, $user_id) . PHP_EOL;
             }
         }
         if (!empty($items)) {
             foreach ($items as $item) {
                 $item = isset($this->assignmentsMap[$item]) ? $this->assignmentsMap[$item] : $item;
                 if (empty($item) || in_array($item, (array) $this->forceAssign, true)) {
                     continue;
                 }
                 $this->authManager->assign(RbacFactory::Role($item), $user_id);
                 echo sprintf('    > role `%s` assigned to user id: %s.', $item, $user_id) . PHP_EOL;
             }
         }
     }
     if ($useCache) {
         if ($this->cache->exists('assignments-0')) {
             $this->cacheIterator(function ($key) {
                 $this->cache->delete($key);
             });
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Deletes everything
  *
  * @return mixed
  */
 public function deleteAll()
 {
     $this->_db->createCommand()->delete($this->tableName);
     $this->_data = [];
     $this->_cache->delete($this->cacheKey);
 }
Exemplo n.º 4
0
 /**
  * @param int|string $userId
  * @param string $key
  * @return bool
  */
 protected function deleteFromCache($userId, $key)
 {
     return $this->cache->delete($this->buildCacheKey($userId, $key));
 }
 /**
  * @param mixed $key
  *
  * @return boolean
  *
  * @see yii\caching\Cache::delete()
  */
 public function delete($key)
 {
     return $this->cache->delete($key);
 }
 /**
  * Delete row by name
  * @param $name
  * @return mixed
  */
 public function delete($name)
 {
     return $this->_cache->delete($this->prefix . $name);
 }
Exemplo n.º 7
-1
 protected function commit()
 {
     /* @fixme: implement batch operations */
     foreach ($this->toRemove as $category => $keyvalue) {
         foreach ($keyvalue as $key => $value) {
             $this->db->createCommand()->delete($this->tableName, ['category' => $category, 'key' => $key])->execute();
         }
     }
     foreach ($this->toSave as $category => $keyvalue) {
         foreach ($keyvalue as $key => $value) {
             $obj = (new Query())->from($this->tableName)->where(['category' => $category, 'key' => $key])->one($this->db);
             $command = $this->db->createCommand();
             if ($obj) {
                 $command = $command->update($this->tableName, ['value' => @serialize($value)], ['category' => $category, 'key' => $key]);
             } else {
                 $command = $command->insert($this->tableName, ['category' => $category, 'key' => $key, 'value' => @serialize($value)]);
             }
             $command->execute();
         }
     }
     if (count($this->toRemove) + count($this->toSave) > 0) {
         $this->cache->delete('settings');
     }
     $this->toRemove = [];
     $this->toSave = [];
 }