background preloader

Couchdb

Facebook Twitter

Django tip: Caching and two-phased template rendering | Holovaty. We've launched user accounts at EveryBlock, and we faced the interesting problem of needing to cache entire pages except for the "You're logged in as [username]" bit at the top of the page. For example, the Chicago homepage takes a nontrivial amount of time to generate and doesn't change often -- which means we want to cache it -- but at the same time, we need to display the dynamic bit in the upper right: One solution would be to pull in the username info dynamically via Ajax. This way, you could cache the entire page and rely on the client to pull in the username bits.

The downsides are that it relies on JavaScript and it requires two hits to the application for each page view. Another solution would be to use Django's low-level cache API to cache the results of the queries directly in our view function. The solution we ended up using is two-phased template rendering. The way it works is to split the page rendering into two steps: Relax with CouchDB. A Scala front-end to a smart memcached - Lift.

Why CouchDB Rocks. Last week I wrote an article called Why CouchDB Sucks , which many people correctly said should have been called "What CouchDB Sucks at Doing". Nearly everyone pointed out that it was not designed to do the things that I was mentioning in the article. This time around, I'd like to focus on some of the features about CouchDB that I think absolutely rock. One of the most annoying parts of dealing with a traditional SQL database is that you invariably need to change your schemata. This can be done usually with some ALTER TABLE statements, but other times it requires scripts and careful use of transactions, etc. The other advantage of having no schema is that some types of data just aren't well suited to having a strict schema enforced upon them.

When is the last time you tried to install MySQL or PostgreSQL drivers for your web development platform of choice? But the best part about this is that we already have so many amazing and well-tested tools to deal with HTTP. Using CouchDB with Django - Eric Florenzano's Website. Ahhh, Django : my favorite web framework. And CouchDB : my favorite new database technology. How can I pair these two awesomes together to make an awesome-er? One of the features that I would like to add to this site when it's time for an upgrade is a lifestream. It seems like everyone is doing it these days (isn't this great logic!) , so I probably should too. Originally this was going to be written in the standard Django way--write some models, fill it with data, and slice and dice that data to make it pretty.

After thinking about it, I decided not to go that route. This is the perfect use case for a schemaless database, and CouchDB fits that bill just perfectly. First let's set some database settings: COUCHDB_HOST = ' TWITTER_USERNAME = 'ericflo' So far, so good. From couchdb import client from django.conf import settings class CouchDBImproperlyConfigured ( Exception ): pass try : HOST = settings . Now we need a way to query this data.