This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

© 2014-2015 Thomas Khyn © 2009 David Cramer

An identity mapper for the Django ORM. This is a fork of django-idmapper, which is no longer maintained.

What is it?

django-idmap is a Django application which:

  • loads only once the instances in memory the first time they are needed
  • share them througout your interpreter until the request is finished

Indeed, the default django behavior is to expose different instances for the same database entry between the start and the end of the request. It has one main consequence: the temporary attributes you may set are lost if you want to access the same database object in another place in your code.

Warning

Deserialization (such as from the cache) will not use the identity mapper.

Tested with django 1.8+ and latest minor versions of python 2 and 3.

Installation

As straightforward as it can be, using pip:

pip install django-idmap

You then need to add 'idmap' to your INSTALLED_APPS.

Usage

To use the exposed 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.

You can chose between 2 caching modes:

  • Weak references mode: the instance will be removed from the cache once there are no more references to it. This is the default behavior
  • Strong references mode: the instance will only be removed from the cache when it is flushed

Note that django-idmap clears the cache when the request_finished or post_syncdb signal is sent. This default behavior can be modified by disconnecting the exposed idmap.flush_cache function from these signals.

Examples

You can import idmap.models as you would import django.db.models. idmap.models exposes all what is exposed by django.db.models plus the SharedMemoryModel model class.

You may mix and match SharedMemoryModels with regular Models:

from idmap import models

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

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

If you want to use strong references for a particular model, simply set use_strong_refs to True in the derived model class:

from idmap import models

class MyModel(models.SharedMemoryModel):
   use_strong_refs = True
   [...]

With strong references, the model will be loaded only once from the database, until it is explicitly erased from the cache.

You may want to use the functions or class methods:

  • idmap.flush_cache() to erase the whole cache
  • SharedMemoryModel.flush_instance_cache() to erase the cache for one model
  • SharedMemoryModel.flush_cached_instance(instance) to erase one instance from the cache

References

David Cramer’s django-idmapper

Original code and concept: http://code.djangoproject.com/ticket/17

Release History

Release History

0.4.1

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.4

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3c1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
django-idmap-0.4.1.zip (14.3 kB) Copy SHA256 Checksum SHA256 Source Jan 19, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting