From e470bd495c77cfec04f05e522d7cd4a3bec646e2 Mon Sep 17 00:00:00 2001 From: Pete Gautier Date: Thu, 12 Oct 2023 15:40:59 -0700 Subject: [PATCH] fix: use Drupal getRequestTime where possible --- src/MomentoCacheBackend.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/MomentoCacheBackend.php b/src/MomentoCacheBackend.php index f02008e..03b5134 100644 --- a/src/MomentoCacheBackend.php +++ b/src/MomentoCacheBackend.php @@ -70,8 +70,11 @@ public function get($cid, $allow_invalid = FALSE) private function valid($item) { // TODO: see https://www.drupal.org/project/memcache/issues/3302086 for discussion of why I'm using // $_SERVER instead of Drupal::time() and potential suggestions on how to inject the latter for use here. - // $requestTime = \Drupal::time()->getRequestTime(); - $requestTime = $_SERVER['REQUEST_TIME']; + try { + $requestTime = \Drupal::time()->getRequestTime(); + } catch (ContainerNotInitializedException $e) { + $requestTime = $_SERVER['REQUEST_TIME']; + } $isValid = TRUE; if ($item->expire != CacheBackendInterface::CACHE_PERMANENT && $item->expire < $requestTime) { $item->valid = FALSE;