Hi !
Not really a bug as it is still in beta but I am not understanding the cache mechanism.
No common interface between the 2 routers.
It makes it complicated to use with a container as you cannot implement a logic inside a factory to return one or the other.
Example of what I had in mind :
$container->add('League\Route\RouterInterface', function () {
if ($prod) {
// Return cached router
}
// return normal router
});
The cached container does not implement RequestHandlerInterface
So if you used the League\Route\Router in a middleware pipeline, then you cannot do it with the cached router.
It can easily be done by implementing your own class extending League\Route\Cache\Router but I think the cached router should be as closed as possible as the normal router and implementors shouldn't have to add custom code.
The cache container caches itself
Why does the container caches (e.g. serialize) itself instead of just serializing the routes that are already registered within it ?
A closure can't be serialized, and if you add a ContainerInterface to the League\Route\Router instance then you absolutely cannot use the cached router because in a container I am pretty sure 99% of the time there are closures (used as factory or whatever).
I think that only the routes array should be cached, something simple with a var_export() then a require_once // or similar.
And probably no need for SimpleCache implementation to deal with it.
Conclusion
Therefore I am just wondering, is there something I didn't not understand or did not implement well ?
Is the cache mechanism going to stay this way ? Or other solution provided ?
(Sorry for the long post)
Hi !
Not really a bug as it is still in beta but I am not understanding the cache mechanism.
No common interface between the 2 routers.
It makes it complicated to use with a container as you cannot implement a logic inside a factory to return one or the other.
Example of what I had in mind :
The cached container does not implement
RequestHandlerInterfaceSo if you used the
League\Route\Routerin a middleware pipeline, then you cannot do it with the cached router.It can easily be done by implementing your own class extending
League\Route\Cache\Routerbut I think the cached router should be as closed as possible as the normal router and implementors shouldn't have to add custom code.The cache container caches itself
Why does the container caches (e.g. serialize) itself instead of just serializing the routes that are already registered within it ?
A closure can't be serialized, and if you add a
ContainerInterfaceto theLeague\Route\Routerinstance then you absolutely cannot use the cached router because in a container I am pretty sure 99% of the time there are closures (used as factory or whatever).I think that only the routes array should be cached, something simple with a
var_export()then arequire_once // or similar.And probably no need for
SimpleCacheimplementation to deal with it.Conclusion
Therefore I am just wondering, is there something I didn't not understand or did not implement well ?
Is the cache mechanism going to stay this way ? Or other solution provided ?
(Sorry for the long post)