From d1beabfc8fde95811c205ed2360871ef3ccf5814 Mon Sep 17 00:00:00 2001 From: John Piasetzki Date: Thu, 20 Oct 2016 00:07:07 -0400 Subject: [PATCH] Add lru_cache to get --- sanic/config.py | 1 + sanic/router.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/sanic/config.py b/sanic/config.py index 8261c2c0..3dbf06c8 100644 --- a/sanic/config.py +++ b/sanic/config.py @@ -22,3 +22,4 @@ class Config: """ REQUEST_MAX_SIZE = 100000000 # 100 megababies REQUEST_TIMEOUT = 60 # 60 seconds + ROUTER_CACHE_SIZE = 1024 diff --git a/sanic/router.py b/sanic/router.py index ece5caad..45248cde 100644 --- a/sanic/router.py +++ b/sanic/router.py @@ -1,5 +1,7 @@ import re from collections import namedtuple +from functools import lru_cache +from .config import Config from .exceptions import NotFound, InvalidUsage Route = namedtuple('Route', ['handler', 'methods', 'pattern', 'parameters']) @@ -75,6 +77,7 @@ class Router: parameters=parameters) self.routes.append(route) + @lru_cache(maxsize=Config.ROUTER_CACHE_SIZE) def get(self, request): """ Gets a request handler based on the URL of the request, or raises an