Skip to content

Commit db38ab2

Browse files
authored
feat: caching (#20)
1 parent a8a6f96 commit db38ab2

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/Cache/Cache.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function createResponse(string $path, bool $supportWebp, Request $request
3030
{
3131
$stream = $this->storage->readStream($path);
3232

33-
$now = new \DateTime();
33+
$lastModified = (new \DateTimeImmutable())->setTimestamp($this->storage->lastModified($path));
3434

3535
$response = new StreamedResponse();
3636
$response->headers->set(
@@ -40,8 +40,9 @@ public function createResponse(string $path, bool $supportWebp, Request $request
4040
$response->headers->set('Content-Length', (string) $this->storage->fileSize($path));
4141
$response->setPublic();
4242
$response->setMaxAge($this->ttl);
43-
$response->setExpires($now->modify("+$this->ttl seconds"));
44-
$response->setLastModified($now->setTimestamp($this->storage->lastModified($path)));
43+
$response->setExpires((new \DateTimeImmutable())->modify("+$this->ttl seconds"));
44+
$response->setLastModified($lastModified);
45+
$response->setEtag(md5((string) $lastModified->getTimestamp()));
4546
$response->isNotModified($request);
4647

4748
$response->setCallback(
@@ -53,7 +54,7 @@ static function () use ($stream) {
5354
fpassthru($stream);
5455
fclose($stream);
5556
// @codeCoverageIgnoreEnd
56-
}
57+
},
5758
);
5859

5960
return $response;

0 commit comments

Comments
 (0)