Skip to content

A custom version of Django's FetchFromCacheMiddleware that allows for simple bypassing of the cache.

Notifications You must be signed in to change notification settings

jnhasty/django-custom-cache-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

This is a slightly modified version of Django's built-in FetchFromCacheMiddleware that allows for simple bypassing of the cache for requests that don't rely on views (and thus you can't use the @never_cache decorator). Just install, and create a list of regex urls that you don't want cached.

Installation

  1. Place the file somewhere you app can find it.

  2. Then add Django's "UpdateCacheMiddleware" and "CustomFetchFromCacheMiddleware" to your settings.py

MIDDLEWARE_CLASSES = ( 'django.middleware.cache.UpdateCacheMiddleware', '...', '...', 'path.to.customcachemiddleware.CustomFetchFromCacheMiddleware' )

  1. Add a list of urls you want the cache to bypass.

CACHE_BYPASS_URLS = ( r'/no/cache/url/',
)

  1. Profit!

I use it in conjunction with uwsgi's in-memory cache and django-tastypie:

http://projects.unbit.it/uwsgi/wiki/CachingFramework https://github.com/toastdriven/django-tastypie

I wrote about my use case for this on my blog:

http://www.jnhasty.com/2012/11/08/caching-api-requests-with-django-tastypie-nginx-and-uwsgi/

And big ups to this article for helping me come to this solution: http://soyrex.com/articles/django-nginx-memcached/

About

A custom version of Django's FetchFromCacheMiddleware that allows for simple bypassing of the cache.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages