Add lru_cache to get

This commit is contained in:
John Piasetzki 2016-10-20 00:07:07 -04:00
parent baf1ce95b1
commit d1beabfc8f
2 changed files with 4 additions and 0 deletions

View File

@ -22,3 +22,4 @@ class Config:
""" """
REQUEST_MAX_SIZE = 100000000 # 100 megababies REQUEST_MAX_SIZE = 100000000 # 100 megababies
REQUEST_TIMEOUT = 60 # 60 seconds REQUEST_TIMEOUT = 60 # 60 seconds
ROUTER_CACHE_SIZE = 1024

View File

@ -1,5 +1,7 @@
import re import re
from collections import namedtuple from collections import namedtuple
from functools import lru_cache
from .config import Config
from .exceptions import NotFound, InvalidUsage from .exceptions import NotFound, InvalidUsage
Route = namedtuple('Route', ['handler', 'methods', 'pattern', 'parameters']) Route = namedtuple('Route', ['handler', 'methods', 'pattern', 'parameters'])
@ -75,6 +77,7 @@ class Router:
parameters=parameters) parameters=parameters)
self.routes.append(route) self.routes.append(route)
@lru_cache(maxsize=Config.ROUTER_CACHE_SIZE)
def get(self, request): def get(self, request):
""" """
Gets a request handler based on the URL of the request, or raises an Gets a request handler based on the URL of the request, or raises an