Commit bdef739a authored by japerry's avatar japerry
Browse files

2999614

parent 6288d096
......@@ -59,6 +59,15 @@ abstract class TimestampInvalidatorBase implements TimestampInvalidatorInterface
return round(microtime(TRUE) + $offset, 3);
}
/**
* {@inheritdoc}
*/
public function getRequestTime() {
// If this is called prior to the request being pushed to the stack fallback
// to built-in globals (if available) or the system time.
return $_SERVER['REQUEST_TIME'] ?? time();
}
/**
* {@inheritdoc}
*/
......
......@@ -58,4 +58,17 @@ interface TimestampInvalidatorInterface {
*/
public function getCurrentTimestamp($offset = 0.0);
/**
* Get the current request time
*
* Memcache operates within the bootstrap container, so only the REQUEST_TIME
* global is (possibly) available. The request object and time service aren't.
* Return the global or time() if need be.
*
* @see https://www.drupal.org/node/2999614 for more info.
*
* @return int
* A Unix timestamp.
*/
public function getRequestTime();
}
......@@ -119,7 +119,7 @@ class MemcacheBackend implements CacheBackendInterface {
$cache->valid = TRUE;
// Items that have expired are invalid.
if ($cache->expire != CacheBackendInterface::CACHE_PERMANENT && $cache->expire <= REQUEST_TIME) {
if ($cache->expire != CacheBackendInterface::CACHE_PERMANENT && $cache->expire <= $this->timestampInvalidator->getRequestTime()) {
$cache->valid = FALSE;
}
......@@ -216,7 +216,7 @@ class MemcacheBackend implements CacheBackendInterface {
public function invalidateMultiple(array $cids) {
foreach ($cids as $cid) {
if ($item = $this->get($cid)) {
$item->expire = REQUEST_TIME - 1;
$item->expire = $this->timestampInvalidator->getRequestTime() - 1;
$this->memcache->set($cid, $item);
}
}
......
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