allow marked middlewares to run when page is cached#12497
Conversation
| */ | ||
| $stack = $this->app->make(StackInterface::class); | ||
| foreach ($middlewareCache as $middleware) { | ||
| if (is_array($middleware)) { |
There was a problem hiding this comment.
Since the elements of $middlewareCache are always arrays, this check is superfluous, isn't it?
There was a problem hiding this comment.
good point have updated
| foreach ($middlewareConfig as $middleware) { | ||
| if (is_array($middleware)) { | ||
| $runBeforeCache = isset($middleware['run_during_cache']) && $middleware['run_during_cache'] === true; | ||
| if ($runBeforeCache) { |
There was a problem hiding this comment.
What about simply
if (!empty($middleware['run_during_cache'])) {this checks both that $middleware['run_during_cache'] is set and that it does not contain a falsy value.
There was a problem hiding this comment.
good point have updated
|
added some functionality that will load the package if required too |
|
I'm just now getting a chance to look at this. I'm not sure how effective this will be - it looks to me like this forces packages to be loaded from the database during this cache checking? The |
| $stack = $this->app->make(StackInterface::class); | ||
| foreach ($middlewareCache as $middleware) { | ||
| if (isset($middleware['package'])) { | ||
| $this->app->setupPackageAutoload($middleware['package']); |
There was a problem hiding this comment.
Isn't this going to always connect to the database? I don't think we're going to be able to accept this unless we can run this without connecting to the DB.
This allows middlewares to run when the page is cached, so as an example you can add in the app.middleware config the following
and then create the middleware as normal e.g
Resolves this issue I raised #12344