Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/Integrated.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,17 @@ public function __construct($l1, $l2, $overhead_threshold = null)
$this->overhead_threshold = $overhead_threshold;
}

public function set(Address $address, $value, $ttl = null, array $tags = [])
public function set(Address $address, $value, $ttl_or_expiration = null, array $tags = [])
{
$expiration = null;
if (!is_null($ttl_or_expiration)) {
if ($ttl_or_expiration < $_SERVER['REQUEST_TIME']) {
$expiration = $_SERVER['REQUEST_TIME'] + $ttl_or_expiration;
} else {
$expiration = $ttl_or_expiration;
}
}

if (!is_null($this->overhead_threshold)) {
$key_overhead = $this->l1->getKeyOverhead($address);

Expand All @@ -32,7 +41,7 @@ public function set(Address $address, $value, $ttl = null, array $tags = [])
// and create a local negative cache entry.
$event_id = $this->l2->delete($this->l1->getPool(), $address);
if (!is_null($event_id)) {
$this->l1->set($event_id, $address, $value, $ttl);
$this->l1->set($event_id, $address, $value, $expiration);
}

// Retain this negative cache item for a number of minutes
Expand All @@ -44,7 +53,6 @@ public function set(Address $address, $value, $ttl = null, array $tags = [])
}
}

$expiration = is_null($ttl) ? null : $_SERVER['REQUEST_TIME'] + $ttl;
$event_id = $this->l2->set($this->l1->getPool(), $address, $value, $expiration, $tags);
if (!is_null($event_id)) {
$this->l1->set($event_id, $address, $value, $expiration);
Expand Down
6 changes: 6 additions & 0 deletions tests/LCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,12 @@ public function testAPCuL1Expiration()
$myaddr2 = new Address('mybin', 'mykey2');
$l1->set(0, $myaddr2, 'value', $_SERVER['REQUEST_TIME'] - 1);
$this->assertNull($l1->get($myaddr2));

// Setting an TTL/expiration more than request time should be treated
// as an expiration.
$pool->set($myaddr, 'value', $_SERVER['REQUEST_TIME'] + 1);
$this->assertEquals('value', $pool->get($myaddr));
$this->assertEquals($_SERVER['REQUEST_TIME'] + 1, $l1->getEntry($myaddr)->expiration);
}

/**
Expand Down