Replies: 2 comments
|
I like the idea. If the implementation is simple, I'd accept a PR for this. Make sure to include tests and updated docs. |
0 replies
|
Hey, @freekmurze I'm working on PR to support multiple configs for the response cache. and I want to have your feedback about the following snippet which should extract config name dynamilcy from the route: Route::middleware(['cacheResponse:config-1'])->group(function () {
Route::middleware(['cacheResponse:config-2'])->group(function () {
Route::get('/test', function () {
dd(getConfigName()); // config-3
})->middleware('cacheResponse:config-3,300');
});
});
function getConfigName(): string
{
$middleware = collect(Route::current()->middleware())
->filter(fn($middleware) => is_string($middleware))
->last(fn($middleware) => Str::startsWith($middleware, 'cacheResponse') || Str::startsWith($middleware,
CacheResponse::class));
if (!$middleware) {
return 'default';
}
$args = explode(':', $middleware)[1] ?? 'default';
return Str::before($args, ',');
}
// cache this route for 5 minutes
Route::get('/my-special-snowflake', 'SnowflakeController@index')->middleware('cacheResponse:300');Same for this: // add a "bar" tag to this route
Route::get('/test2', 'SnowflakeController@index')->middleware('cacheResponse:,bar');Must be replaced by this: // cache this route for 5 minutes
Route::get('/my-special-snowflake', 'SnowflakeController@index')->middleware('cacheResponse:,300');
// add a "bar" tag to this route
Route::get('/test2', 'SnowflakeController@index')->middleware('cacheResponse:,,bar'); |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Wouldn't be great to have multiple configs for caching ?.
with a middleware maybe that can accept a config name as param. this will allow for much flexibility when trying to cache specific routes with a specific profile. or having a profile for API requests and another one for web requests.
Something like: https://github.com/spatie/laravel-webhook-client for example.
routes.php
api.php
Where the parameters
web&apiare mapped to config names:All reactions