Go Straight to Content

What I'll Be Ranting About

Good development practices bring us quality code, confident systems, and missed launch windows. When do you refactor and when do you factor in the passing time? As engineers we need to design what is possible and capable. As programmers we need to turn imagination into reality without a physical product. As developers we need to bridge the gab between that engineered vision and the end product.

I also blog more personally over at my tumblr page.

I am available for small contracts, consultations, tutoring, and other development services. My "skills" as a technical writer are also available. If you've got anything you'd like to talk to me about or for me to see, drop me a line.

Tuesday, January 31, 2012

ANN: Django Better Cache 0.5.1 with expanded docs


I've made a small incremental release on Django Better Cache, adding a from_miss() method to handle cache misses in CacheModel objects. Now, you can define your cache model and how it initializes data when the cache is empty, and perform all your lookups through the CacheModel, expecting misses to auto-populate for you.

You can see a quick example of the new functionality below, but I have also made large improvements to the documentation hosted over at ReadTheDocs, so go read the full docs right now, if you are interested.

from bettercache.objects import CacheModel
from django.contrib import auth

class User(CacheModel):
    username = Key()
    email = Field()
    full_name = Field()

    def from_miss(self, username):
        user = auth.models.User.objects.get(username=username)
        self.email = user.email
        self.full_name = user.get_full_name()


If this get() does not find the object in the cache, it will create a new
User instance and call from_miss() with the key parameter username to
initialize it, and then save and return that object for you. The next call,
it will find it in the cache.

user = User.get(username="bob")

0 comments:

Blog Archive