Friday, February 17th, 2012

Django caching and CSRF

Some readers may have noticed a recent bug with the comments framework this blog is using from the Django project. I have concluded that this bug is due to the site-wide caching I have enabled. The comments which were added over the past weeks were posted after the cache expired for the page which a reader was commenting on.

In this event, I will be building the caching from the ground-up, using Django's caching framework. This will include manually specifying which parts of the site to actually cache. My main concern and why I have caching enabled is database queries from the blog content sections. Since I use some custom templatetags to render links to bookmarks and packages, and soon reviews, I needed to cache these results to limit the database queries, to allow the site to perform quicker.

My idea would be to enable caching directly in these template tags, where all the heavy database queries are. I chose to create the blog using this method for my personal ease of use. I found other formatting languages such as markdown and BBcode too limiting. I really enjoy the power and freedom which Django templates provide me. It allows me to create links which absolutely cannot break. I personally hate visiting a website which has tons of broken links due to the the posts having static links to the external websites. To remedy this, I created a packages list, and a bookmark system. If I change the link for a package or bookmark, all pages which reference them will automatically reflect that change.

This is the main reason I wanted to create a custom blog platform. I saw a major flaw in other blogging software on the market, and wanted my blog to avoid the broken link flaw. The only draw back, is that the site does need to use extensive caching in order to limit the hits on the database, and to keep the site running smoothly for all visitors.

Originally today, there was suppose to be a different blog post published, but I postponed it until Monday. This post will be published in it's place to address a recent bug in my blogging software. This bug will be resolved over the weekend, and you should see less glitches on the site as a result.

Comment #1: Posted 2 years, 5 months ago by Jonathan Street

While I share your dislike for broken links I think your solution is still less than optimal. Rather than clicking one link to go to any external site I'm forced to click through two links. I can see over time the tags and descriptions being useful but I think for most use cases the current system is a pain.

Broken links will still appear unless you monitor the sites and update any broken links. Having an easy way to update a broken link across the entire site is a really nice feature but I would love to see the 'known good' links inserted into articles rather than the annoying indirect link.

Prior to this article I had assumed that the setup was in place for SEO reasons. Whilst the alternative presented above places the system in a much better light I can't shake the feeling that SEO is a major reason. The use of nofollow links only strengthens this view. Why would you link to something and then explicitly state 'This link is not associated with this site'? Acceptable for user generated content but not for links you're posting yourself.

Comment #2: Posted 2 years, 5 months ago by Kevin Veroneau

Thanks for the comment and suggestion Jonathan. I will enable direct links in the next revision. Currently only bookmark links are single click to external sites. Package links are not, as I also wanted to direct users to related content such as tutorials and reviews on this site first.

Comment #3: Posted 2 years, 5 months ago by Jonathan Street

Hi Kevin

Judging from the django link at the top of this post it looks like you have already rolled out a new version. I think the change is a very nice compromise. Thanks for making it.

About Me

My Photo
Names Kevin, hugely into UNIX technologies, not just Linux. I've dabbled with the demons, played with the Sun, and now with the Penguins.




Kevin Veroneau Consulting Services
Do you require the services of a Django contractor? Do you need both a website and hosting services? Perhaps I can help.

This Month

If you like what you read, please consider donating to help with hosting costs, and to fund future books to review.

Python Powered | © 2012-2013 Kevin Veroneau