Skip to content

Commit

Permalink
Crud routes are not cached
Browse files Browse the repository at this point in the history
Distinguish between get and post cache
  • Loading branch information
andrevanzuydam committed Nov 29, 2023
1 parent 25d49e2 commit c261075
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Tina4/Routing/Crud.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ public static function route($path, ORM $object, $function, $secure = false): vo
* @description {$path} CRUD
* @tags CRUD
* @secure
* @no-cache
*/
Route::get(
$path . "/form",
Expand All @@ -198,6 +199,7 @@ function (Response $response, Request $request) use ($object, $function) {

/**
* @description {$path} CRUD
* @no-cache
*/
Route::post(
$path,
Expand All @@ -223,6 +225,7 @@ function (Response $response, Request $request) use ($object, $function) {
* @description {$path} CRUD
* @tags CRUD
* @secure
* @no-cache
*/
Route::get(
$path,
Expand All @@ -239,6 +242,7 @@ function (Response $response, Request $request) use ($object, $function) {
* @description {$path} CRUD
* @tags CRUD
* @secure
* @no-cache
*/
Route::get(
$path . "/{id}",
Expand All @@ -258,6 +262,7 @@ function (Response $response, Request $request) use ($object, $function) {
* @description {$path} CRUD
* @tags CRUD
* @secure
* @no-cache
*/
Route::post(
$path . "/{id}",
Expand All @@ -281,6 +286,7 @@ function (Response $response, Request $request) use ($object, $function) {
* @description {$path} CRUD
* @tags CRUD
* @secure
* @no-cache
*/
Route::delete(
$path . "/{id}",
Expand Down
6 changes: 3 additions & 3 deletions Tina4/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ final public function resolveRoute(?string $method, ?string $url, ?Config $confi
if ($routerResponse = $this->handleRoutes($method, $url, $customHeaders, $customRequest)) {
if ($routerResponse->cached) {
$this->createCacheResponse(
$url,
$url.$method,
$routerResponse->httpCode,
$routerResponse->content,
$this->addCORS($routerResponse->headers),
Expand Down Expand Up @@ -514,7 +514,7 @@ public function handleRoutes($method, $url, array $customHeaders=[], $customRequ
}
else
if ($route["cached"]) {
$cacheResult = $this->getCacheResponse($url);
$cacheResult = $this->getCacheResponse($url.$method);
if ($cacheResult !== null && $url !== "/cache/clear" && $url !== "/migrate" && $url !== "/migrate/create") {
Debug::message("$this->GUID Got cached result for $url", TINA4_LOG_DEBUG);
return new RouterResponse(
Expand All @@ -538,7 +538,7 @@ public function handleRoutes($method, $url, array $customHeaders=[], $customRequ
return new RouterResponse("", HTTP_FORBIDDEN, $headers);
} else {
if ($route["cached"]) {
$cacheResult = $this->getCacheResponse($url);
$cacheResult = $this->getCacheResponse($url.$method);
if ($cacheResult !== null && $url !== "/cache/clear" && $url !== "/migrate" && $url !== "/migrate/create") {
Debug::message("$this->GUID Got cached result for $url", TINA4_LOG_DEBUG);
return new RouterResponse(
Expand Down

0 comments on commit c261075

Please sign in to comment.