Django cache keys: making them safer

I posted some [code to make your Django cache keys safer] [my-snippet] over at [Django snippets] [django-snippets] the other day.

This code evolved at [work] [ajc] over several months as we encountered a few caching challenges with [memcache] [memcache].

* The first problem was that occasionally some of our cache keys would be too long. Memcache only allows keys up to 250 characters. So the first iteration of this just checked the length and [md5’d] [md5-python] it if it was over the limit.
* Because a lot of our cache keys are based on slugs or titles provided by our staff users, they can occasionally include characters that memcache doesn’t like. Zapping the bad characters and replacing them with an underscore solved the problem. The ord(char) < 33 logic was lifted directly from the [memcache Python library] [py-memcache].
* The third problem we had to address came up during our [Django 1.0] [django-10] upgrade. For almost every project, we have the same [application] [gallery-ajc] installed on [several] [gallery-homes] [different] [gallery-access] [sites] [gallery-edge]. As we rolled out the 1.0 code our pre-1.0 cache keys were being accessed by our now-1.0 code and the cached objects weren't unpickling nicely at all in some cases. Hence the automatic addition of the CACHE_MIDDLEWARE_KEY_PREFIX setting. That way we could alter that setting in our 1.0 code and get fresh keys containing 1.0 compatible objects.

[my-snippet]: http://www.djangosnippets.org/snippets/1212/
[django-snippets]: http://www.djangosnippets.org/
[memcache]: http://www.danga.com/memcached/
[md5-python]: http://www.python.org/doc/2.4.4/lib/module-md5.html
[gallery-ajc]: http://projects.ajc.com/gallery/list/recent/
[gallery-homes]: http://projects.ajchomefinder.com/gallery/list/recent/
[gallery-access]: http://projects.accessatlanta.com/gallery/list/recent/
[gallery-edge]: http://projects.eveningedge.com/gallery/list/recent/
[django-10]: http://www.djangoproject.com/weblog/2008/sep/03/1/
[ajc]: http://www.ajc.com
[py-memcache]: http://www.tummy.com/Community/software/python-memcached/

Posted in Django, Programming, Python, Technology | Comments Off on Django cache keys: making them safer

Django developer wanted at ajc.com

We’re looking for a great Django/Python developer to join our small team at [ajc.com] [ajc].

Check out the job posting at [Django Gigs] [django-gig] or at [Craigslist] [craigslist].

Here are some of the benefits to working on our team:

* We’re a small team — but full of great people like [Maura] [maura] and [Zellyn] [zellyn]

* Our projects are highly visible — if you’ve spent more than a minute on [ajc.com] [ajc], then I guarantee you’ve seen one of our applications or utilities at work.

* The variety of projects — Range from content [publishing tools] [galleries] for staff and users, to [data interactives] [executive-pay], to [user generated content] [vent], to behind the scenes tools that enhance the site.

* Telecommuting — As much as we all love working together and getting a group vibe going, we also spit off during the week to get distraction free and in the zone.

* Take the train to work — When we’re not telecommuting, we work in an office that’s easy to get to on MARTA

* We get paid to work on and in Django and Python — That’s still pretty damn cool.

If you’re interested hit me up at: **cheisel** at **ajc** dot com.

[ajc]: http://www.ajc.com
[django-gig]: http://djangogigs.com/gigs/483/
[craigslist]: http://atlanta.craigslist.org/eng/931884539.html
[maura]: http://www.paragiraffe.com/
[zellyn]: http://zellyn.com
[galleries]: http://projects.ajc.com/gallery/list/recent/
[executive-pay]: http://projects.ajc.com/executive-pay/
[vent]: http://projects.ajc.com/vent/metro/

Posted in Django, Journalism, Programming, Python, Technology | 1 Comment

Gmail theme showing incorrect weather

Is anyone else having an issue where their [Gmail theme](http://mail.google.com/support/bin/answer.py?hl=en&ctx=mail&answer=112508) is showing incorrect weather?

It’s 11:38 on a Sunday in Atlanta. There are clear blue skies out and the tree theme is showing me thunderclouds.

Gmail's incorrect weather

Posted in Technology | 10 Comments

Rich in doughy goodness

In honor of a [special someone’s](http://ericaendicott.com) birthday, [there were biscuits](http://flickr.com/photos/cmheisel/3050496620/), [homemade](http://flickr.com/photos/cmheisel/3050495966/in/photostream/) [buttermilk biscuits](http://www.foodnetwork.com/recipes/alton-brown/southern-biscuits-recipe/index.html).

Continue reading

Posted in Personal | Tagged , | Comments Off on Rich in doughy goodness

What are pages per visit?

If you’re tracking [page views](http://heisel.org/blog/2008/11/18/what-is-a-visitor/), [visitors](http://heisel.org/blog/2008/11/18/what-is-a-visitor/) and [visits](http://heisel.org/blog/2008/11/19/what-is-a-visit/) then you can calculate the next important metric in our jaunt down jargon lane… pages per visit.

This one is just what it sounds like — the average number of page views generated by your visitors during an average visit.

It’d be easy to assume that more pages per visit would be better? After all, [more can quite often be better](http://smittenkitchen.com/2007/05/my-kingdom-for-a-glass-of-milk/).

But you have to think about the goals for your site. Take Google — they want to get you to the information you’re seeking as fast as possible. So they’d prefer a low pages per visit. But since they’re hoping that the experience will tempt you back for more, they’re probably also hoping for a high number of visits, with a low pages per visit.

If your site makes money from (display) advertising, and you’re not an aggregator like Google, then you probably do want to concern yourself with pages per visit.

Why? Because if your design and content can tempt folks to linger and “turn” more pages after they start their visit you can make more money.

Snagging users can be costly, building and retaining a sizeable audience on the Internet is difficult?

Why? Because, if I can paraphrase the [Hitchhikers Guide to the Galaxy](http://en.wikiquote.org/wiki/The_Hitchhiker’s_Guide_to_the_Galaxy#Chapter_8):

“The Internet is big. Really big. You just won’t believe how vastly [hugely mindbogglingly big it is](http://visualgadgets.blogspot.com/2008/06/graphs-and-networks.html). I mean you may think it’s a long way down the road to the chemist, but that’s just peanuts to the Internet.”

Posted in Journalism, Management, Technology | 1 Comment