Skip to main content

django-dynamodb-cache

Fast, safe, cost-effective DynamoDB cache backend for Django

Tests Coverage Package version Supported Python versions Supported django versions License

Introduce

This project is a cache backend using aws dynamodb.

This is compatible with the django official cache framework.

Did you set the boto3 permission?

Enter the django official command createcachetable and get started easily.

Why should I use this?

  • There are few management points, because dynamodb is a fully managed service.
  • Because you only pay for what you use, it saves money on light projects such as side projects or back offices.
  • If you need more performance, you can easily switch to DAX.

Installation

pip install django-dynamodb-cache

Setup on Django

On Django settings.py

INSTALLED_APPS = [
    ...
    "django_dynamodb_cache"
]

CACHES = {
    "default": {
        "BACKEND": "django_dynamodb_cache.backend.DjangoCacheBackend",
        "LOCATION": "table-name",                  # (mandatory)
        "TIMEOUT": 300,                            # (optional) seconds
        "KEY_PREFIX": "django_dynamodb_cache",     # (optional)
        "VERSION": 1,                              # (optional)
        "KEY_FUNCTION": "path.to.function",        # (optional) f"{prefix}:{key}:{version}"
        "OPTIONS": {
            "aws_region_name": "us-east-1",                    # (optional)
            "aws_access_key_id": "aws_access_key_id",          # (optional)
            "aws_secret_access_key": "aws_secret_access_key",  # (optional)
            "is_on_demand": False,                 # (optional) default: True
            "read_capacity_units": 1,              # (optional)
            "write_capacity_units": 1,             # (optional)
            "encode": "django_dynamodb_cache.encode.PickleEncode"  # (optional)
        }
    }
}

Aws credentials

The same method as configuring-credentials provided in the boto3 documentation is used. https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html#configuring-credentials

Create cache table command

Run manage command to create cache table on Dynamodb before using

python manage.py createcachetable

Future improvements

In this project, the following can be improved in the future.

  • A full scan is included to achieve cache.clear(). This can lead to performance degradation when there is a lot of cached data.

How to contribute

This project is welcome to contributions!

Please submit an issue ticket before submitting a patch.

Pull requests are merged into the main branch and should always remain available.

After passing all test code, it is reviewed and merged.

Debug

Tests must be run in a sandbox environment.

To run the Dynamodb sandbox:

docker compose up --build

Metadata

Release files for django-dynamodb-cache 0.6.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-dynamodb-cache 0.6.0
File Size Uploaded
django_dynamodb_cache-0.6.0.tar.gz 11.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-dynamodb-cache 0.6.0
File Interpreter ABI Platform
django_dynamodb_cache-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 23.2 kB

Release files / django_dynamodb_cache-0.6.0.tar.gz

Download URL django_dynamodb_cache-0.6.0.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
0082055cf1c7e2676c48bdca2fbdc1491c14fcb54fb5dfb339c5956e9ecae354
BLAKE2b-256 checksum
How to use checksums
787461343ac47b5149cb9cb5fd988615bcd21c61e7f192c2aab766690dd7b2d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.8.18 Linux/6.2.0-1018-azure

Release files / django_dynamodb_cache-0.6.0-py3-none-any.whl

Download URL django_dynamodb_cache-0.6.0-py3-none-any.whl
Size 12.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a3b39a710ff3decb9ad53de2206ccad92bcb75420743d89c6de27e77481b4f49
BLAKE2b-256 checksum
How to use checksums
63507da0def21391e7b80e46accc50a241242fe888f5c182fec99a2c2f5507db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.8.18 Linux/6.2.0-1018-azure

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.3

2 release files

0.2.0

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