1Dancer::Route::Cache(3)User Contributed Perl DocumentatioDnancer::Route::Cache(3)
2
3
4

NAME

6       Dancer::Route::Cache - route caching mechanism for Dancer
7

VERSION

9       version 1.3513
10

SYNOPSIS

12           my $cache = Dancer::Route::Cache->new(
13               path_limit => 300, # optional, defaults to 600 (routes to cache)
14               size_limit => 5M,  # optional, defaults to 10M (10MB)
15           );
16
17           # storing a path
18           # /new/item/ is the path, $route is a compiled route
19           $cache->store_path( 'get', '/new/item/', $route );
20           my $cached_route = $cache->route_from_path('/new/item/');
21

DESCRIPTION

23       When Dancer first starts, it has to compile a regexp list of all the
24       routes.  Then, on each request it goes over the compiled routes list
25       and tries to compare the requested path to a route.
26
27       A major drawback is that Dancer has to go over the matching on every
28       request, which (especially on CGI-based applications) can be very time
29       consuming.
30
31       The caching mechanism allows one to cache some requests to specific
32       routes (but NOT specific results) and run those routes on a specific
33       path. This allows us to speed up Dancer quite a lot.
34

METHODS/SUBROUTINES

36   new(@args)
37       Creates a new route cache object.
38
39           my $cache = Dancer::Route::Cache->new(
40               path_limit => 100,   # only 100 paths will be cached
41               size_limit => '30M', # max size for cache is 30MB
42           );
43
44       Please check the "ATTRIBUTES" section below to learn about the
45       arguments for "new()".
46
47   route_from_path($path)
48       Fetches the route from the path in the cache.
49
50   store_path( $method, $path => $route )
51       Stores the route in the cache according to the path and $method.
52
53       For developers: the reason we're using an object for this and not
54       directly using the registry hash is because we need to enforce the
55       limits.
56
57   parse_size($size)
58       Parses the size wanted to bytes. It can handle Kilobytes, Megabytes or
59       Gigabytes.
60
61       NOTICE: handles bytes, not bits!
62
63           my $bytes = $cache->parse_size('30M');
64
65           # doesn't need an existing object
66           $bytes = Dancer::Route::Cache->parse_size('300G'); # works this way too
67
68   route_cache_size
69       Returns a rough calculation the size of the cache. This is used to
70       enforce the size limit.
71
72   route_cache_paths
73       Returns all the paths in the cache. This is used to enforce the path
74       limit.  Please be careful if you use "mount" in Plack::Builder and some
75       applications - routes are linked with applications and same path may be
76       in some applications but with different handlers!
77

ATTRIBUTES

79   size_limit($limit)
80       Allows one to set a size limit of the cache.
81
82       Returns the limit (post-set).
83
84           $cache->size_limit('10K');      # sets limit
85           my $limit = $cache->size_limit; # gets limit
86
87   path_limit($limit)
88       A path limit. That is, the amount of paths that whose routes will be
89       cached.
90
91       Returns the limit (post-set).
92
93           $cache->path_limit('100');      # sets limit
94           my $limit = $cache->path_limit; # gets limit
95

AUTHOR

97       Dancer Core Developers
98
100       This software is copyright (c) 2010 by Alexis Sukrieh.
101
102       This is free software; you can redistribute it and/or modify it under
103       the same terms as the Perl 5 programming language system itself.
104
105
106
107perl v5.32.1                      2021-01-27           Dancer::Route::Cache(3)
Impressum