Skip to content

Commit 67f2f54

Browse files
authored
Merge pull request #79 from php-http/clean-handling
explicitly use 0 instead of adding null
2 parents 2c4cb06 + 87b9c61 commit 67f2f54

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Test with PHP 8.1 and 8.2
66
- Made phpspec tests compatible with PSR-7 2.0 strict typing
7+
- Detect `null` and use 0 explicitly to calculate expiration
78

89
## 1.7.5 - 2022-01-18
910

src/CachePlugin.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ final class CachePlugin implements Plugin
5858
* bool respect_cache_headers: Whether to look at the cache directives or ignore them
5959
* int default_ttl: (seconds) If we do not respect cache headers or can't calculate a good ttl, use this value
6060
* string hash_algo: The hashing algorithm to use when generating cache keys
61-
* int cache_lifetime: (seconds) To support serving a previous stale response when the server answers 304
61+
* int|null cache_lifetime: (seconds) To support serving a previous stale response when the server answers 304
6262
* we have to store the cache for a longer time than the server originally says it is valid for.
6363
* We store a cache item for $cache_lifetime + max age of the response.
6464
* string[] methods: list of request methods which can be cached
@@ -230,7 +230,7 @@ private function calculateCacheItemExpiresAfter(?int $maxAge): ?int
230230
return null;
231231
}
232232

233-
return $this->config['cache_lifetime'] + $maxAge;
233+
return ($this->config['cache_lifetime'] ?: 0) + ($maxAge ?: 0);
234234
}
235235

236236
/**
@@ -368,7 +368,7 @@ private function configureOptions(OptionsResolver $resolver): void
368368
$resolver->setAllowedTypes('default_ttl', ['int', 'null']);
369369
$resolver->setAllowedTypes('respect_cache_headers', ['bool', 'null']);
370370
$resolver->setAllowedTypes('methods', 'array');
371-
$resolver->setAllowedTypes('cache_key_generator', ['null', 'Http\Client\Common\Plugin\Cache\Generator\CacheKeyGenerator']);
371+
$resolver->setAllowedTypes('cache_key_generator', ['null', CacheKeyGenerator::class]);
372372
$resolver->setAllowedTypes('blacklisted_paths', 'array');
373373
$resolver->setAllowedValues('hash_algo', hash_algos());
374374
$resolver->setAllowedValues('methods', function ($value) {

0 commit comments

Comments
 (0)