Ejemplo n.º 1
0
    public function testSetAndGetExpiredItems()
    {
        $capabilities = $this->_storage->getCapabilities();

        $ttl = $capabilities->getTtlPrecision();
        $this->_options->setTtl($ttl);

        $items = array(
            'key1' => 'value1',
            'key2' => 'value2',
            'key3' => 'value3'
        );
        $this->assertSame(array(), $this->_storage->setItems($items));

        // wait until expired
        $wait = $ttl + $capabilities->getTtlPrecision();
        usleep($wait * 2000000);

        $rs = $this->_storage->getItems(array_keys($items));
        if (!$capabilities->getUseRequestTime()) {
            $this->assertEquals(array(), $rs);
        } else {
            ksort($rs);
            $this->assertEquals($items, $rs);
        }

        if ($capabilities->getExpiredRead()) {
            $rs = $this->_storage->getItems(array_keys($items), array('ttl' => 0));
            ksort($rs);
            $this->assertEquals($items, $rs);
        }
    }