Giter VIP home page Giter VIP logo

django-dynamodb-cache's Introduction

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.

django-dynamodb-cache's People

Contributors

esc5221 avatar xncbf avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.