Skip to main content

django-cache-lock

PyPI Build Status Donate with Bitcoin

A simple lock extension for django's cache to prevent concurrent editing.

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

    def nolock(self):
        pass

foo = Foo()
with lock_model(foo, blocking=False):
    nolock()

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.

Supported backends

  • django.core.cache.backends.db
  • django.core.cache.backends.file
  • django.core.cache.backends.locmem
  • django.core.cache.backends.memcached
  • django-redis
  • django-redis-cache

ATTENTIONS

locmem backend

  • DO NOT USE locmem backend in a product environment.

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.

redis backend

  • We didn't test distributed redis lock.

TODOS:

  • use 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.2.5.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_cache_lock-0.2.5-py2.py3-none-any.whl (7.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file django-cache-lock-0.2.5.tar.gz.

File metadata

  • Download URL: django-cache-lock-0.2.5.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for django-cache-lock-0.2.5.tar.gz
Algorithm Hash digest
SHA256 27a688c4b0f547c7066a0da827e6ff21c22805529afdfc3992d1754d81b6d3c6
MD5 b770560a038ec6a341a4a73e75d4828a
BLAKE2b-256 0263966ed2b3180e7f5c3401682cd1be615bf8c8c0db21602128dc0eeca22b87

See more details on using hashes here.

File details

Details for the file django_cache_lock-0.2.5-py2.py3-none-any.whl.

File metadata

  • Download URL: django_cache_lock-0.2.5-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for django_cache_lock-0.2.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 eaa34a908972ef740a9e1a3131668bff6974c44ad61b09c330f165eee441467c
MD5 4561f83a2db911194924fbee0875bec6
BLAKE2b-256 c376ca915af2539f912e2d398939d59c7eeae1c82bb36d91bddbca61724f5dd8

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.5 This release

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.2

2 files

0.1.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page