Commit 21fbb5dd authored by catch's avatar catch

Issue #2259823 by beejeebus, Wim Leers: Make cache->created be to the millisecond.

parent c47466e9
......@@ -68,6 +68,12 @@ public function getMultiple(&$cids, $allow_invalid = FALSE);
/**
* Stores data in the persistent cache.
*
* Core cache implementations set the created time on cache item with
* microtime(TRUE) rather than REQUEST_TIME_FLOAT, because the created time
* of cache items should match when they are created, not when the request
* started. Apart from being more accurate, this increases the chance an
* item will legitimately be considered valid.
*
* @param string $cid
* The cache ID of the data to store.
* @param mixed $data
......
......@@ -180,7 +180,7 @@ protected function doSet($cid, $data, $expire, $tags) {
$checksum = $this->checksumTags($flat_tags);
$fields = array(
'serialized' => 0,
'created' => REQUEST_TIME,
'created' => round(microtime(TRUE), 3),
'expire' => $expire,
'tags' => implode(' ', $flat_tags),
'checksum_invalidations' => $checksum['invalidations'],
......@@ -575,8 +575,10 @@ public function schemaDefinition() {
'default' => 0,
),
'created' => array(
'description' => 'A Unix timestamp indicating when the cache entry was created.',
'type' => 'int',
'description' => 'A timestamp with millisecond precision indicating when the cache entry was created.',
'type' => 'numeric',
'precision' => 14,
'scale' => 3,
'not null' => TRUE,
'default' => 0,
),
......
......@@ -121,7 +121,7 @@ public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array
$item = (object) array(
'cid' => $cid,
'data' => $data,
'created' => REQUEST_TIME,
'created' => round(microtime(TRUE), 3),
'expire' => $expire,
);
$item->tags = $this->flattenTags($tags);
......
......@@ -142,7 +142,7 @@ public function testSetGet() {
$this->assert(is_object($cached), "Backend returned an object for cache id test1.");
$this->assertIdentical($with_backslash, $cached->data);
$this->assertTrue($cached->valid, 'Item is marked as valid.');
$this->assertEqual($cached->created, REQUEST_TIME, 'Created time is correct.');
$this->assertTrue($cached->created >= REQUEST_TIME && $cached->created < microtime(TRUE), 'Created time is correct.');
$this->assertEqual($cached->expire, Cache::PERMANENT, 'Expire time is correct.');
$this->assertIdentical(FALSE, $backend->get('test2'), "Backend does not contain data for cache id test2.");
......@@ -151,7 +151,7 @@ public function testSetGet() {
$this->assert(is_object($cached), "Backend returned an object for cache id test2.");
$this->assertIdentical(array('value' => 3), $cached->data);
$this->assertTrue($cached->valid, 'Item is marked as valid.');
$this->assertEqual($cached->created, REQUEST_TIME, 'Created time is correct.');
$this->assertTrue($cached->created >= REQUEST_TIME && $cached->created < microtime(TRUE), 'Created time is correct.');
$this->assertEqual($cached->expire, REQUEST_TIME + 3, 'Expire time is correct.');
$backend->set('test3', 'foobar', REQUEST_TIME - 3);
......@@ -159,7 +159,7 @@ public function testSetGet() {
$cached = $backend->get('test3', TRUE);
$this->assert(is_object($cached), 'Backend returned an object for cache id test3.');
$this->assertFalse($cached->valid, 'Item is marked as valid.');
$this->assertEqual($cached->created, REQUEST_TIME, 'Created time is correct.');
$this->assertTrue($cached->created >= REQUEST_TIME && $cached->created < microtime(TRUE), 'Created time is correct.');
$this->assertEqual($cached->expire, REQUEST_TIME - 3, 'Expire time is correct.');
$this->assertIdentical(FALSE, $backend->get('test4'), "Backend does not contain data for cache id test4.");
......@@ -169,7 +169,7 @@ public function testSetGet() {
$this->assert(is_object($cached), "Backend returned an object for cache id test4.");
$this->assertIdentical($with_eof, $cached->data);
$this->assertTrue($cached->valid, 'Item is marked as valid.');
$this->assertEqual($cached->created, REQUEST_TIME, 'Created time is correct.');
$this->assertTrue($cached->created >= REQUEST_TIME && $cached->created < microtime(TRUE), 'Created time is correct.');
$this->assertEqual($cached->expire, Cache::PERMANENT, 'Expire time is correct.');
$this->assertIdentical(FALSE, $backend->get('test5'), "Backend does not contain data for cache id test5.");
......@@ -179,7 +179,7 @@ public function testSetGet() {
$this->assert(is_object($cached), "Backend returned an object for cache id test5.");
$this->assertIdentical($with_eof_and_semicolon, $cached->data);
$this->assertTrue($cached->valid, 'Item is marked as valid.');
$this->assertEqual($cached->created, REQUEST_TIME, 'Created time is correct.');
$this->assertTrue($cached->created >= REQUEST_TIME && $cached->created < microtime(TRUE), 'Created time is correct.');
$this->assertEqual($cached->expire, Cache::PERMANENT, 'Expire time is correct.');
$with_variable = array('foo' => '$bar');
......@@ -274,7 +274,7 @@ public function testGetMultiple() {
$this->assert(isset($ret['test7']), "Existing cache id test7 is set.");
// Test return - ensure that objects has expected properties.
$this->assertTrue($ret['test2']->valid, 'Item is marked as valid.');
$this->assertEqual($ret['test2']->created, REQUEST_TIME, 'Created time is correct.');
$this->assertTrue($ret['test2']->created >= REQUEST_TIME && $ret['test2']->created < microtime(TRUE), 'Created time is correct.');
$this->assertEqual($ret['test2']->expire, Cache::PERMANENT, 'Expire time is correct.');
// Test return - ensure it does not contain nonexistent cache ids.
$this->assertFalse(isset($ret['test19']), "Nonexistent cache id test19 is not set.");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment