django-cache-lock
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
Metadata
Release files for django-cache-lock 0.2.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django-cache-lock-0.2.5.tar.gz | 7.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_cache_lock-0.2.5-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 14.9 kB
Release files / django-cache-lock-0.2.5.tar.gz
| Download URL | django-cache-lock-0.2.5.tar.gz |
|---|---|
| Size | 7.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
27a688c4b0f547c7066a0da827e6ff21c22805529afdfc3992d1754d81b6d3c6
|
|
BLAKE2b-256 checksum How to use checksums |
0263966ed2b3180e7f5c3401682cd1be615bf8c8c0db21602128dc0eeca22b87
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / django_cache_lock-0.2.5-py2.py3-none-any.whl
| Download URL | django_cache_lock-0.2.5-py2.py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
eaa34a908972ef740a9e1a3131668bff6974c44ad61b09c330f165eee441467c
|
|
BLAKE2b-256 checksum How to use checksums |
c376ca915af2539f912e2d398939d59c7eeae1c82bb36d91bddbca61724f5dd8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for django-cache-lock 0.2.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.