Skip to main content

A simple lock extension for django's cache.

Project description

django-cache-lock

PyPI Build Status

A simple lock extension for django's cache.

Installation

Install django-cache-lock by using pip

pip install django-cache-lock

Quick Start

You can work with django-cache-lock by using with-statement or decorator.

from django_lock import lock

with lock("global"):
    pass

@lock("global")
def foo():
    pass

A shortcut to lock model instance

from django.db import models
from django_lock import model_lock

class Foo(models.Model):
    bar = models.CharField(max_length=8)

    @lock_model
    def lock_pk(self):
        pass

    @lock_model("bar", blocking=False)
    def lock_bar(self):
        pass

Configurations

key default desc
DJANGOLOCK_PREFIX "lock:" lock's key prefix stored in cache
DJANGOLOCK_SLEEP 0.1 default interval time to acquire a lock if a lock is holded by others
DJANGOLOCK_RELEASEONDEL True release lock when __del__ is called if True

Advanced usage

For more usages, please read the code.

ATTENTIONS

memcached backend

  • Memcached does not support milliseconds expire time, and its' expire time is not very exact. So memcached lock's timeout time is not as exact as other backends.

TODOS:

  • use lua script and memcached's cas to release lock
  • reacquire and extend lock
  • database backend cache support

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-cache-lock-0.1.1.tar.gz (6.1 kB view hashes)

Uploaded Source

Built Distribution

django_cache_lock-0.1.1-py2.py3-none-any.whl (6.0 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page