diff --git a/src/CacheEntry.php b/src/CacheEntry.php index 9e8cf6da..e1e11023 100644 --- a/src/CacheEntry.php +++ b/src/CacheEntry.php @@ -147,13 +147,17 @@ public function getTTL() // No TTL if we have a way to re-validate the cache return 0; } + if ($this->staleIfErrorTo !== null) { // Keep it when stale if error - return $this->staleIfErrorTo->getTimestamp() - time(); + $ttl = $this->staleIfErrorTo->getTimestamp() - time(); + } else { + // Keep it until it become stale + $ttl = $this->staleAt->getTimestamp() - time(); } - // Keep it until it become stale - return $this->staleAt->getTimestamp() - time(); + // Don't return 0, it's reserved for infinite TTL + return $ttl != 0 ? $ttl : -1; } public function __sleep()