Skip to content

Commit

Permalink
#15 Don't return 0 if it isn't for caching
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevinrob committed Jul 21, 2015
1 parent 3ceb501 commit 1b756e5
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/CacheEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 1b756e5

Please sign in to comment.