43 lines
822 B
PHP
Raw Normal View History

<?php
use Dumbo\Dumbo;
use Dumbo\Middleware\CacheMiddleware;
2024-09-08 09:24:38 +01:00
require __DIR__ . "/vendor/autoload.php";
$app = new Dumbo();
/**
* CacheMiddleware is a middleware that adds cache control headers to the HTTP response.
* This middleware is applied only to routes that begin with "/cached",
* meaning that only these routes will have cache control headers.
*/
2024-09-08 09:24:38 +01:00
$app->use(
"/cached",
CacheMiddleware::withHeaders(
type: "public",
mustRevalidate: true,
maxAge: 3600,
strictEtag: true
)
);
$app->get("/cached/greet", function ($c) {
sleep(5);
return $c->json([
"message" => "Welcome cached route!",
]);
});
2024-09-08 09:24:38 +01:00
$app->get("/uncached/greet", function ($c) {
sleep(5);
return $c->json([
2024-09-08 09:24:38 +01:00
"message" => "Uncached route!",
]);
});
$app->run();