[Answer]-Django Performance, url.py evaluation and cache

1👍

this is how django processes the HttpRequest https://docs.djangoproject.com/en/dev/topics/http/urls/#how-django-processes-a-request

the first 3 steps are:

  1. Django determines the root URLconf module to use. Ordinarily, this
    is the value of the ROOT_URLCONF setting, but if the incoming
    HttpRequest object has an attribute called urlconf (set by
    middleware request processing), its value will be used in place of
    the ROOT_URLCONF setting.

  2. Django loads that Python module and looks for the variable
    urlpatterns. This should be a Python list of django.conf.urls.url()
    instances.

  3. Django runs through each URL pattern, in order, and stops at the
    first one that matches the requested URL.

for your purpose you would need to write your own middleware between 2 and 3 which first looks for a pattern in cache, if it doesnot find, it should go on with step 3.

But I dont think you need this. I would go for caching views which is much heavier than urls.

Leave a comment