Kelp caches the matching patterns for a given path. If patterns contain named parameters, though, then the cache can grow without bounds.
e.g., if I have a route for /user/:id, then the cache will store something like:
/user/1024:GET =>
[
bless( {
'regex' => qr/(?^:^\/user\/(?<id>[^\/]+)\/?$)/,
'_tokens' => [
'id'
],
'param' => [
'1024'
],
'pattern' => '/user/:id',
'via' => undef,
'name' => 'user',
'defaults' => {},
'named' => {
'id' => '1024'
},
'bridge' => 0,
'check' => {},
'to' => 'MyApp::user'
}, 'Kelp::Routes::Pattern' )
]
Kelp::Routes provides a cache() method, so it would be simple to inject an alternative cache object there, but I'm wondering if it
would be good to have the default setup not require that.
Looking around at the LRU cache landscape, I found Cache::LRU:
I know CHI is widely used, but Cache::LRU is so nice and simple. It doesn't provide a tied hash interface that I can tell, but that would be simple to add.
There's also Tie::Cache::LRU from Schwern, but he notes he's not updating it and recommends using CHI instead.
Alternatively, we could have the default setup not do caching at all, or simply clear the cache entirely when a size limit reached.
Thoughts? I think my leaning would be to have some sort of automatic expiration.