kriwil logo

Hi, I'm Aldiantoro Nugroho. Here I talk all about development. Mostly Technical. Enjoy!

  1. django's cached_property

    If you find yourself using @property a lot in your model and the property costs database queries, you might want to consider using cached_property instead.

    For example:

    from django.utils.functional import cached_property
    class Book(models.Model):
        def references(self):
            # more queries here
            return references

    So instead re-query everytime you call the property, it'll use cache instead, as long as the instance still exists.

    — 20140612 – aldi —
If you have any comment, tweet me @kriwil.