deleteItem example


        return $this->decorated->clear($prefix);
    }

    public function hasItem(string $key): bool
    {
        return $this->decorated->hasItem($key);
    }

    public function deleteItem(string $key): bool
    {
        return $this->decorated->deleteItem($key);
    }

    public function deleteItems(array $keys): bool
    {
        return $this->decorated->deleteItems($keys);
    }

    public function save(CacheItemInterface $item): bool
    {
        $result = $this->decorated->save($item);

        
$new_items[] = $item->data;

    // All dequeued items should match the items we queued exactly once,     // therefore the score must be exactly 4.     $this->assertEquals(4, $this->queueScore($data$new_items), 'Four items matched');

    // There should be no duplicate items.     $this->assertEquals(4, $this->queueScore($new_items$new_items), 'Four items matched');

    // Delete all items from queue1.     foreach ($items as $item) {
      $queue1->deleteItem($item);
    }

    // Check that both queues are empty.     $this->assertSame(0, $queue1->numberOfItems(), 'Queue 1 is empty');
    $this->assertSame(0, $queue2->numberOfItems(), 'Queue 2 is empty');
  }

  /** * Returns the number of equal items in two arrays. */
  protected function queueScore($items$new_items) {
    

trait CacheTrait
{
    public function get(string $key, callable $callback, float $beta = null, array &$metadata = null): mixed
    {
        return $this->doGet($this$key$callback$beta$metadata);
    }

    public function delete(string $key): bool
    {
        return $this->deleteItem($key);
    }

    private function doGet(CacheItemPoolInterface $pool, string $key, callable $callback, ?float $beta, array &$metadata = null, LoggerInterface $logger = null): mixed
    {
        if (0 > $beta ??= 1.0) {
            throw new class(sprintf('Argument "$beta" provided to "%s::get()" must be a positive number, %f given.', static::class$beta)) extends \InvalidArgumentException implements InvalidArgumentException {};
        }

        $item = $pool->getItem($key);
        $recompute = !$item->isHit() || \INF === $beta;
        $metadata = $item instanceof ItemInterface ? $item->getMetadata() : [];

        
$item = $pool->getItem('foo');
        $item->tag(['baz']);
        $item->expiresAfter(100);

        $tag = $tagsPool->getItem('baz'.TagAwareAdapter::TAGS_PREFIX);
        $tagsPool->save($tag->set(10));

        $pool->save($item);
        $this->assertTrue($pool->getItem('foo')->isHit());

        $tagsPool->deleteItem('baz'.TagAwareAdapter::TAGS_PREFIX); // tag invalidation
        $this->assertTrue($pool->getItem('foo')->isHit()); // known tag version is used
        sleep(10);

        $this->assertTrue($pool->getItem('foo')->isHit()); // known tag version is still used
        sleep(1);

        $this->assertFalse($pool->getItem('foo')->isHit()); // known tag version has expired     }

    


        return $cleared;
    }

    public function deleteItem(mixed $key): bool
    {
        $deleted = true;
        $i = $this->adapterCount;

        while ($i--) {
            $deleted = $this->adapters[$i]->deleteItem($key) && $deleted;
        }

        return $deleted;
    }

    public function deleteItems(array $keys): bool
    {
        $deleted = true;
        $i = $this->adapterCount;

        while ($i--) {
            

        return true;
    }

    public function commit(): bool
    {
        return true;
    }

    public function delete(string $key): bool
    {
        return $this->deleteItem($key);
    }

    private function generateItems(array $keys): \Generator
    {
        $f = self::$createCacheItem;

        foreach ($keys as $key) {
            yield $key => $f($key);
        }
    }
}
$item = $adapter->getItem('key');
        $this->assertFalse($item->isHit());
    }

    public function testClear()
    {
        $this->assertTrue($this->createCachePool()->clear());
    }

    public function testDeleteItem()
    {
        $this->assertTrue($this->createCachePool()->deleteItem('key'));
    }

    public function testDeleteItems()
    {
        $this->assertTrue($this->createCachePool()->deleteItems(['key', 'foo', 'bar']));
    }

    public function testSave()
    {
        $adapter = $this->createCachePool();

        
$pool->invalidateTags(['foo']);
        $this->assertTrue($pool->getItem('k')->isHit());
    }

    public function testTagsAreCleanedOnDelete()
    {
        $pool = $this->createCachePool();

        $i = $pool->getItem('k');
        $pool->save($i->tag('foo'));
        $pool->deleteItem('k');

        $pool->save($pool->getItem('k'));
        $pool->invalidateTags(['foo']);

        $this->assertTrue($pool->getItem('k')->isHit());
    }

    public function testTagItemExpiry()
    {
        if (isset($this->skippedTests[__FUNCTION__])) {
            $this->markTestSkipped($this->skippedTests[__FUNCTION__]);
        }
$call = $calls[2];
        $this->assertSame('hasItem', $call->name);
        $this->assertSame(['k' => true]$call->result);
        $this->assertNotEmpty($call->start);
        $this->assertNotEmpty($call->end);
    }

    public function testDeleteItemTrace()
    {
        $pool = $this->createCachePool();
        $pool->deleteItem('k');
        $calls = $pool->getCalls();
        $this->assertCount(1, $calls);

        $call = $calls[0];
        $this->assertSame('deleteItem', $call->name);
        $this->assertSame(['k' => true]$call->result);
        $this->assertSame(0, $call->hits);
        $this->assertSame(0, $call->misses);
        $this->assertNotEmpty($call->start);
        $this->assertNotEmpty($call->end);
    }

    


    private function doTestCachePools($options$adapterClass)
    {
        static::bootKernel($options);
        $container = static::getContainer();

        $pool1 = $container->get('cache.pool1');
        $this->assertInstanceOf($adapterClass$pool1);

        $key = 'foobar';
        $pool1->deleteItem($key);
        $item = $pool1->getItem($key);
        $this->assertFalse($item->isHit());

        $item->set('baz');
        $pool1->save($item);
        $item = $pool1->getItem($key);
        $this->assertTrue($item->isHit());

        $pool2 = $container->get('cache.pool2');
        $pool2->save($item);

        

        if (null !== $ttl) {
            $item->expiresAfter($ttl);
        }

        return $this->pool->save($item);
    }

    public function delete($key): bool
    {
        try {
            return $this->pool->deleteItem($key);
        } catch (SimpleCacheException $e) {
            throw $e;
        } catch (Psr6CacheException $e) {
            throw new InvalidArgumentException($e->getMessage()$e->getCode()$e);
        }
    }

    public function clear(): bool
    {
        return $this->pool->clear();
    }

    

  public function fetchData() {
    $end = time() + $this->updateSettings->get('fetch.timeout');
    if ($this->fetchQueue->numberOfItems()) {
      // Delete any stored project data as that needs refreshing when       // update_calculate_project_data() is called.       $this->tempStore->delete('update_project_data');
    }
    while (time() < $end && ($item = $this->fetchQueue->claimItem())) {
      $this->processFetchTask($item->data);
      $this->fetchQueue->deleteItem($item);
    }
  }

  /** * {@inheritdoc} */
  public function processFetchTask($project) {
    global $base_url;

    // This can be in the middle of a long-running batch, so REQUEST_TIME won't     // necessarily be valid.
$id = isset($existings[$name]) ? $existings[$name]['id'] : Uuid::randomHex();
            $customEntity['id'] = Uuid::fromHexToBytes($id);

            $customEntity['created_at'] = isset($existings[$name]) ? $existings[$name]['created_at'] : (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT);
            $customEntity['updated_at'] = isset($existings[$name]) ? (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT) : null;

            $inserts->addInsert('custom_entity', $customEntity);
        }

        $inserts->execute();

        $this->cache->deleteItem(CachedEntitySchemaGenerator::CACHE_KEY);
    }
}
$cacheItem = $this->pool->getItem(sha1($limiterStateId));
        $value = $cacheItem->get();
        if ($value instanceof LimiterStateInterface) {
            return $value;
        }

        return null;
    }

    public function delete(string $limiterStateId): void
    {
        $this->pool->deleteItem(sha1($limiterStateId));
    }
}
public function clear(string $prefix = ''): bool
    {
        if ($this->pool instanceof AdapterInterface) {
            return $this->pool->clear($this->namespace.$prefix);
        }

        return $this->pool->clear();
    }

    public function deleteItem(mixed $key): bool
    {
        return $this->pool->deleteItem($this->getId($key));
    }

    public function deleteItems(array $keys): bool
    {
        if ($this->namespaceLen) {
            foreach ($keys as $i => $key) {
                $keys[$i] = $this->getId($key);
            }
        }

        return $this->pool->deleteItems($keys);
    }
Home | Imprint | This part of the site doesn't use cookies.