From 1a8a3c5b1d8b8d0a73b021d597b65d8cf09cde72 Mon Sep 17 00:00:00 2001 From: Serdar Dogruyol Date: Sun, 16 Sep 2018 15:34:43 +0300 Subject: [PATCH] Add cache size limit check to caching routes --- src/kemal/route_handler.cr | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/kemal/route_handler.cr b/src/kemal/route_handler.cr index 2e3ea3b..233289e 100644 --- a/src/kemal/route_handler.cr +++ b/src/kemal/route_handler.cr @@ -4,7 +4,8 @@ module Kemal class RouteHandler include HTTP::Handler - INSTANCE = new + INSTANCE = new + CACHED_ROUTES_LIMIT = 1024 property routes, cached_routes def initialize @@ -33,7 +34,11 @@ module Kemal route = @routes.find(lookup_path) - @cached_routes[lookup_path] = route if route.found? + if route.found? && @cached_routes.size < CACHED_ROUTES_LIMIT + @cached_routes[lookup_path] = route + else + @cached_routes.clear + end route end