Dancer...:Cache(3pm)
π Dancer::Route::Cache β the manual, but make it slay π
okay bestie, so this is Dancer::Route::Cache, and it lives in the User Contributed Perl Documentation section of the manual (section 3pm, if you're keeping score). It's a route caching mechanism for Dancer, and honestly? it's giving speedrun energy. πβοΈβ¨
β¨ NAME β¨
Dancer::Route::Cache β route caching mechanism for Dancer π
πΈ VERSION πΈ
version 1.3522
π¦ SYNOPSIS π¦
my $cache = Dancer::Route::Cache->new(
path_limit => 300, # optional, defaults to 600 (routes to cache)
size_limit => 5M, # optional, defaults to 10M (10MB)
);
# storing a path
# /new/item/ is the path, $route is a compiled route
$cache->store_path( 'get', '/new/item/', $route );
my $cached_route = $cache->route_from_path('/new/item/');
π DESCRIPTION π
so here's the tea, bestie β β
When Dancer first starts up, it has to compile a regexp list of all the routes. Then, on every single request, it goes over that compiled routes list and tries to compare the requested path to a route. every. single. time. π
and the major drawback?? Dancer has to go over the matching on every request, which β especially on CGI-based applications β can be very time consuming. it's giving "why are we like this". π
so the caching mechanism swoops in like the main character β¨ and lets you cache some requests to specific routes (but NOT specific results, ok? important!) and run those routes on a specific path. Which allows us to speed up Dancer quite a lot. ate. π
π METHODS/SUBROUTINES π
π new(@args)
Creates a new route cache object. brand new, fresh out the box, iconic.
my $cache = Dancer::Route::Cache->new(
path_limit => 100, # only 100 paths will be cached
size_limit => '30M', # max size for cache is 30MB
);
Please check the "ATTRIBUTES" section below to learn about the arguments for new() β it's literally right there, go look. π
π§ route_from_path($path)
Fetches the route from the path in the cache. that's it, that's the whole vibe.
β store_path( $method, $path => $route )
Stores the route in the cache according to the path and $method.
For developers: the reason we're using an object for this and not directly using the registry hash is because we need to enforce the limits. yeah, the object is doing the boundary-setting. respect. π«Ά
π parse_size($size)
Parses the size wanted to bytes. It can handle Kilobytes, Megabytes or Gigabytes.
NOTICE: handles bytes, not bits! β οΈ do not confuse them, bestie, that's a whole different number.
my $bytes = $cache->parse_size('30M');
# doesn't need an existing object
$bytes = Dancer::Route::Cache->parse_size('300G'); # works this way too
look at that β it works without an existing object too. independent. self-sufficient. π
π route_cache_size
Returns a rough calculation the size of the cache. This is used to enforce the size limit. rough numbers, but she's doing her best π
π route_cache_paths
Returns all the paths in the cache. This is used to enforce the path limit.
Please be careful if you use "mount" in Plack::Builder and some applications β routes are linked with applications and same path may be in some applications but with different handlers! π this is the "it's complicated" part, ok? same path, different handlers, do not get got.
β¨ ATTRIBUTES β¨
πΈ size_limit($limit)
Allows one to set a size limit of the cache.
Returns the limit (post-set). so you set it, and it hands it right back to you. reciprocity. π
$cache->size_limit('10K'); # sets limit
my $limit = $cache->size_limit; # gets limit
π¦ path_limit($limit)
A path limit. That is, the amount of paths that whose routes will be cached. (yes, we said it exactly like that, no notes π)
Returns the limit (post-set).
$cache->path_limit('100'); # sets limit
my $limit = $cache->path_limit; # gets limit
π AUTHOR π
Dancer Core Developers β absolute legends, no cap. π«‘
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2010 by Alexis Sukrieh.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. slay, open source, we love to see it. π
and that's the whole page bestie!! this was perl v5.40.1, dated 2026-05-05, from the User Contributed Perl Documentation section β mwah, go cache some routes, ily, bye!! π β¨π¦
π¦ where this page comes from
- ubuntu stonking: libdancer-perl 1.3522-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms