Skip to content

Cached Router misunderstanding #353

@debuss

Description

@debuss

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions