public
Description: Singletons in Django
Homepage:
Clone URL: git://github.com/dcramer/django-idmapper.git
David Cramer (author)
Fri May 22 10:39:10 -0700 2009
commit  41ab7e6a1dd07818849495daaff579039a6272f4
tree    eeb3a414065df7f054017962f3e9c75b4ccc08af
parent  37e7f75e0fb4f577c567ca09e4941cf34faf0c91
name age message
file .gitignore Tue Dec 02 03:07:52 -0800 2008 Initial tested and working code. Added pyc to g... [dcramer]
file LICENSE Fri May 22 10:39:10 -0700 2009 Added BSD License [David Cramer]
file README.rst Tue Dec 02 16:26:41 -0800 2008 Updated readme [dcramer]
directory idmapper/ Tue Dec 02 16:22:07 -0800 2008 Fixed an issue when deleting instances. Added m... [dcramer]

Django Identity Mapper

A pluggable Django application which allows you to explicitally mark your models to use an identity mapping pattern. This will share instances of the same model in memory throughout your interpreter.

Please note, that deserialization (such as from the cache) will not use the identity mapper.

Usage

To use the shared memory model you simply need to inherit from it (instead of models.Model). This enable all queries (and relational queries) to this model to use the shared memory instance cache, effectively creating a single instance for each unique row (based on primary key) in the queryset.

For example, if you want to simply mark all of your models as a SharedMemoryModel, you might as well just import it as models.

import idmapper as models

class MyModel(models.SharedMemoryModel):
    name = models.CharField(...)

Because the system is isolated, you may mix and match SharedMemoryModel's with regular Model's.

import idmapper as models

class MyModel(models.SharedMemoryModel):
    name = models.CharField(...)
    fkey = models.ForeignKey('Other')

class Other(models.Model):
    name = models.CharField(...)