Skip to main content

django-querycache

codecov

Cache manager for Django querysets / serialization

This combines Django's cache mechanism, a queryset / model and a serialization format, in order that you don't need to query or serialize data which is (according to either timestamp or MD5 sum of the rows in your query) unchanged

Fingerprinting

This module takes a Django model, queryset or (app_name, model_name) tuple and generates an 8 character md5 hash of the contents. It caches that hash along with the time the hash was generated using a unique key for each query.

TimeStampedFingerprint

Where a model uses a field with auto_now this field can be used as an alternative to generating the md5 hash, saving a bit of processor thrashing and i/o. You might want to check that you're using a DateTimeField rather than a DateField however or your cache might be unexpectedly stale.

CachedQuerySet

Takes a Django model, queryset or (app_name, model_name) tuple and optional params. If a Fingerprinting instance is provided it's used to generate hashes and detect changes; otherwise a Fingerprint instance is generated on init. This allows different cache backends and even different queries to be used for the fingerprint and cache, which is beneficial when there are costly database calls (one example being geographic processing... mvt tiles perhaps?)

GeoJsonCachedQuerySet

This is a special form of CachedQuerySet which should generate valid GeoJSON features from a model or queryset. Note that the geometry field is expected to be a GeoJSON field not a geometry field.

Development

This project uses poetry for deploment

Optional (but recommended): Install pre-commit with

pip install pre-commit
pre-commit install

Publishing

  • Bump the pyproject.yaml version number
  • Run poetry build
  • Run poetry publish

Auth

You may need your API token from pypi, or generate one from pypi. The api token will start with 'pypi'.

poetry publish --build --username __token__ --password pypi-AgE.........Q

You may need to be added as a contributor on pypi - if so please ask @joshbrooks to add you

Testing

From the root directory run tests with

poetry run runtests.py

This uses the test setting in tests. You may wish to set an env variable for a different settings if you want to use a different setup (note tests use the postgis container specified in the github actions)

To run the container as specified in the actions, run a postgres container on 49158 with password post1233

docker run \
    --rm \
    -p 49158:5432 \
    -e POSTGRES_PASSWORD="post1233" \
    postgis/postgis:14-3.2\
    -c fsync=off

Github Actions

Github actions run a test suite for code clarity (black, isort, flake8, mypy) as well as the django tests above

Metadata

Release files for django-querycache 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-querycache 0.3.0
File Size Uploaded
django_querycache-0.3.0.tar.gz 13.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-querycache 0.3.0
File Interpreter ABI Platform
django_querycache-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 29.2 kB

Release files / django_querycache-0.3.0.tar.gz

Download URL django_querycache-0.3.0.tar.gz
Size 13.8 kB
Tags Source
SHA-256 checksum
How to use checksums
4bd594df4a0cd4a9ce7d91c0806554c0ffd8969cc43ef6e853bbefb03e30f47e
BLAKE2b-256 checksum
How to use checksums
348aa788b4a3c466855ea6d8f64906b069dd4d10c769411c539c8880db892be8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.1 CPython/3.11.2 Linux/5.19.0-41-generic

Release files / django_querycache-0.3.0-py3-none-any.whl

Download URL django_querycache-0.3.0-py3-none-any.whl
Size 15.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eefbb9165094eaa9e81c5280ae23e259757c91c6190263e801725b4afa15cf00
BLAKE2b-256 checksum
How to use checksums
83275154e709bcc3fc690089655820f6b1ed0308545a65ca03843303dd0f4f68
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.1 CPython/3.11.2 Linux/5.19.0-41-generic

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page