1 | <?php |
||
10 | class ResponseCache |
||
11 | { |
||
12 | /** @var \Spatie\ResponseCache\ResponseCacheRepository */ |
||
13 | protected $cache; |
||
14 | |||
15 | /** @var \Spatie\ResponseCache\RequestHasher */ |
||
16 | protected $hasher; |
||
17 | |||
18 | /** @var \Spatie\ResponseCache\CacheProfiles\CacheProfile */ |
||
19 | protected $cacheProfile; |
||
20 | |||
21 | public function __construct(ResponseCacheRepository $cache, RequestHasher $hasher, CacheProfile $cacheProfile) |
||
27 | |||
28 | public function enabled(Request $request): bool |
||
32 | |||
33 | public function shouldCache(Request $request, Response $response): bool |
||
45 | |||
46 | public function cacheResponse(Request $request, Response $response, $lifetimeInSeconds = null): Response |
||
47 | { |
||
48 | if (config('responsecache.add_cache_time_header')) { |
||
49 | $response = $this->addCachedHeader($response); |
||
50 | } |
||
51 | |||
52 | $this->cache->put( |
||
53 | $this->hasher->getHashFor($request), |
||
54 | $response, |
||
55 | ($lifetimeInSeconds) ? intval($lifetimeInSeconds) : $this->cacheProfile->cacheRequestUntil($request) |
||
56 | ); |
||
57 | |||
58 | collect(config('responsecache.replacers', []))->map(function ($replacerClass) { |
||
59 | return resolve($replacerClass); |
||
60 | })->each(function (Replacer $replacer) use ($request, $lifetimeInSeconds) { |
||
61 | $this->cache->putKey( |
||
62 | $this->hasher->getHashFor($request).$replacer->searchFor(), |
||
63 | $replacer->replaceBy(), |
||
64 | ($lifetimeInSeconds) ? intval($lifetimeInSeconds) : $this->cacheProfile->cacheRequestUntil($request) |
||
65 | ); |
||
66 | }); |
||
67 | |||
68 | return $response; |
||
69 | } |
||
70 | |||
71 | public function hasBeenCached(Request $request): bool |
||
77 | |||
78 | public function getCachedResponseFor(Request $request): Response |
||
82 | |||
83 | public function getCachedKeyFor(Request $request, string $key): string |
||
87 | |||
88 | /** |
||
89 | * @deprecated Use the new clear method, this is just an alias. |
||
90 | */ |
||
91 | public function flush() |
||
95 | |||
96 | public function clear() |
||
100 | |||
101 | protected function addCachedHeader(Response $response): Response |
||
109 | |||
110 | /** |
||
111 | * @param string|array $uris |
||
112 | * |
||
113 | * @return \Spatie\ResponseCache\ResponseCache |
||
114 | */ |
||
115 | public function forget($uris): self |
||
130 | } |
||
131 |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.