Posted on Sept. 18, 2012
Caching in Django is elegant and simple, especially the site-wide cache for anonymous users. But if you use Google Analytics and other external cookies, it might not be working the way you intended. Read this tutorial to find out how to make your site as fast as it can be.
By enabling the site-wide cache in Django, you probably intended for pages every page to be cached for every anonymous users. That's the point, at least. The problem is, the page cache is set to
Vary: Cookie. That means that if you have a session cookie or anything of the like, the cache will be different for each user.
Fortunately, that's not a problem with Django itself, since anonymous users won't have cookies set. But it is a problem if you're using Google Analytics. That's because Google Analytics sets cookies that trigger the site-wide cache's
Vary: Cookie condition. Luckily, fixing this is as easy as using a small piece of middleware and a touch of inheritance.
Let's create a new middleware file, call it
middleware.py and place it in your project root. Add the following snippet to the file1:
1 2 3 4 5 6 7 8 9 10 11
from django.middleware.cache import UpdateCacheMiddleware import re class SmartUpdateCacheMiddleware(UpdateCacheMiddleware): STRIP_RE = re.compile(r'\b(_[^=]+=.+?(?:; |$))') def process_request(self, request): cookie = self.STRIP_RE.sub('', request.META.get('HTTP_COOKIE', '')) request.META['HTTP_COOKIE'] = cookie
So what does this do? It replaces the middleware that comes with Django. Before passing on the cookies to the rest of the application, it strips out the cookies set by Google Analytics. That way, the
Vary: Cookie condition won't be triggered, as your application won't see any of these cookies. To deploy these changes, simply find your middleware classes in settings.py, and replace
middleware.SmartUpdateCacheMiddleware. Your middleware settings should look like so:
1 2 3 4 5
MIDDLEWARE_CLASSES = ( 'middleware.SmartUpdateCacheMiddleware', # All your other middleware. 'django.middleware.cache.FetchFromCacheMiddleware', )
And that's it. You're done.
please update the middleware.py file. It's not working...
This was written for Django 1.2. I believe Django changed its middleware structure around Django 1.10, so I'm not sure when this stopped working. The concepts might still apply though.
Laisser les choses évoluer dans le bon sens. panerai montres La contingence exige du vendeur qu’il ait un esprit flexible et qu’il fasse les choses comme il se doit, mais pas trop, afin que les gens puissent être convaincus, laissant ainsi une bonne impression au client, transformant les inconvénients en avantages. Le boîtier de la patek philippe montres est en titane. La conception en matériau léger rend la montre plus dynamique. Le diamètre de 47 mm est idéal pour les hommes aux poignets épais, et le matériau léger ne fait pas le poignet. La table est trop lourde.
The music is the key to relax but not anytime when you got bad vibes everything seems bad to you-you don't want to get interact with anything because it makes you uncomfortable. can someone do my homework for me Its natural phenomena when you are worried about something so you don't like anything at all. Because your mind doesn't want to accept anything.
This is a full blog post on this topic. Thank you for sharing this information with us all.
packers and movers Delhi to Surat ,
packers and movers Delhi to Bhopal ,
packers and movers Delhi to Jaipur ,
packers and movers Delhi to Nagpur ,
packers and movers Delhi to Indore , packers and movers Delhi to Chennai
This post is very informative on this topic Thank you for sharing this post with us.
packers and movers Delhi to Lucknow ,
packers and movers Delhi to Jodhpur ,
packers and movers Delhi to Guwahati , packers and movers Delhi to Dehradun , packers and movers Delhi to Ghaziabad ,
packers and movers Delhi to Bhubaneswar
Great job for publishing such a beneficial web site. Your web log isn’t only useful but it is additionally really creative too. There tend to be not many people who can certainly write not so simple posts that artistically. Continue the nice writing Medical Emergency Help
This information is quite interesting and give much benefits to everyone. However, most of the student may face lot of difficulties while doing their essay, project or dissertation so we are here to help you and understand you and give you the best Academic Writing Help with cheapest cost and rate.
We are driven by convenience - we understand this must be the place splendid organization will begin from. Our point is to meet and outperform the wants for our guests through phenomenal organizations and proportions of neighborliness, tidiness of our workplaces, and sensibility of our property as well. If you are scanning for hotels in hamra beirut, by then we can ensure the best benefits in the town. Our cabin is in like manner a supportive scene for guests who mean to stay for long. It is in like manner enveloped by the most remarkable schools, crisis facilities, and government associations.
Hey there, it turned out to be a really fabulous adventure for me personally when I visited your web site. I hope you don't mind if I commend you on the superb quality of the work and additionally to send you the best of luck with everything as you move forward over the coming months. It was certainly a satisfying adventure to explore your blog and I'll most definitely be stopping by once again to ascertain precisely how you are doing. Thanks a bunch and with a bit of luck I shall see you here once more in a little while - Toby Plasterer
Django is an interesting game, I used to play it all the time before. I even gave a review about it on https://casinostories.podbean.com/e/explanation-of-online-slot-features/. And people liked my review.
Thanks for your writing. I would like to say a health insurance broker also works for the benefit of the actual coordinators of any group insurance policies. The health insurance broker is given a directory of benefits sought by an individual or a group coordinator. What any broker can is try to find individuals and also coordinators which best complement those requirements. Then he gifts his advice and if the two of you agree, the particular broker formulates a legal contract between the two parties. varicose veins cream reviews
The road of love was only by himself so he had to step If love is only on the lips, I do not need you to say Hey dear, I still remember or have forgotten The places I vowed and the places I used to go We used to experience and taste the night together So how is the moon with the sun? How you, how you, how you krunker super smash flash 2
Hello, I had been researching the web and I ran into your own blog. Keep up the wonderful work. Fitzrovia barbers
Thank you so much regarding giving me personally an update on this theme on your web page. Please realize that if a new post becomes available or if any modifications occur to the current publication, I would be considering reading a lot more and focusing on how to make good usage of those approaches you reveal. Thanks for your efforts and consideration of other individuals by making this site available. 안전공원
Greetings, it was a truly superb experience for me when I looked around your web blog. I hope you don't mind if I compliment you on the excellent quality of the work you've done here and additionally to send your team bon chance with everything as you develop in the coming months. It was obviously enjoyable to check out your website and I'll definitely be dropping by again before long to find exactly how you're doing. All the best and I will doubtless see you here once again in the future - Dawud Plaster
Internal direct, training, contentment, honour, forbearance plus sentence. Usually a percentage of problems that Tang Soo Write, the actual Mandarin chinese martial art related to self-defense, can educate we additionally instilling in you the strength not just in defend your business women and men capability related with spotting hazard joins to refrain from giving confrontation completely. 토토가족방
Very interesting details you have noted , thankyou for posting .This will be huge for smugglers sending these phones to countries that are not directly supported by Apple currently. Apple will move substantial units this way. This article only takes the American perspective, which is ridiculous. best cbd oil for pain
Can I merely say that of a relief to discover somebody who truly knows what theyre preaching about online. You actually know how to bring an issue to light and earn it crucial. More people must check this out and understand this side with the story. I cant think youre no more common since you also undoubtedly have the gift. Haircut near me
Aw, i thought this was a very good post. In thought I must set up writing like that additionally – taking time and actual effort to generate a excellent article… but so what can I say… I procrastinate alot and also by no means often get something carried out. Buy Linkedin Post Shares
Thank you for the sensible critique. Me & my neighbor were just preparing to do a little research on this. We got a grab a book from our local library but I think I learned more from this post. I am very glad to see such fantastic info being shared freely out there. 토토사이트
Hi there! I just wish to give an enormous thumbs up for the nice info you’ve right here on this post. I shall be coming again to your blog for extra soon. joker123
This posting is incredibly nicely written, and it in addition consists of numerous beneficial information. I appreciated you are specialist manner of creating this blog post. Thanks, you have created it simple and easy for me to comprehend. payday loan consolidation companies
I thought this was an excellent post. In figured I should set up composing like that moreover – requiring some serious energy and genuine exertion to produce a fantastic article… however so what would i be able to state… I delay alot and furthermore in no way, shape or form regularly get something completed. Psl 2020 schedule pdf