public function setDueDate($key, $value, $timestamp, array $tags = null)
{
$document = array('_id' => $key, self::FIELD_NAME_VALUE => $value);
if ($timestamp) {
$document[self::FIELD_NAME_EXPIRED] = new \MongoDate((int) $timestamp);
}
if ($tags) {
$document[self::FIELD_NAME_TAGS] = $tags;
}
$result = $this->collection->getMongoCollection()->update(array('_id' => $key), $document, array('upsert' => true));
if ((double) 1 !== $result['ok']) {
throw new Exception('Error setting value');
}
return $this;
}
public function testSetDueDate_ExistedKey() { $this->cache->setDueDate('php', 'Old Value', time() + 100); $this->assertEquals('Old Value', $this->cache->get('php')); $this->cache->setDueDate('php', 'PHP: Hypertext Processor', time() + 1); $this->assertEquals('PHP: Hypertext Processor', $this->cache->get('php')); usleep(2000000); $this->assertEmpty($this->cache->get('php')); }