Skip to main content

No project description provided

Project description

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.
  • Data is safely stored unlike inmemory db.
  • 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": 120,                            # (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

Project details


Download files

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

Source Distribution

django_dynamodb_cache-0.4.0.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

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

django_dynamodb_cache-0.4.0-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file django_dynamodb_cache-0.4.0.tar.gz.

File metadata

  • Download URL: django_dynamodb_cache-0.4.0.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.8.15 Linux/5.15.0-1024-azure

File hashes

Hashes for django_dynamodb_cache-0.4.0.tar.gz
Algorithm Hash digest
SHA256 718abebfda9bf567d46b31da930426b25c11b9b1daf622b3a4794f1dd2863497
MD5 c2c5bc7a7286f70f13ba4c8477dc7776
BLAKE2b-256 fe1496a2706de20ccb522c75a02f484e70a71e29d8e7c0264793debf57b00a8d

See more details on using hashes here.

File details

Details for the file django_dynamodb_cache-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_dynamodb_cache-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 190410b8f22280e79aa3bed7b4007a6116246ce030ea8715653515da34895b62
MD5 cbc0b5dd20a0708358783966b47a058f
BLAKE2b-256 0a8a9df129c84ba33a9083d3a99eab3ec95e436ff22420dc5a3204d6ebdf82cf

See more details on using hashes here.

Supported by

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