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