https://github.com/xncbf/django-dynamodb-cache
Django cache backend for serverless
https://github.com/xncbf/django-dynamodb-cache
aws cache django python serverless
Last synced: 10 months ago
JSON representation
Django cache backend for serverless
- Host: GitHub
- URL: https://github.com/xncbf/django-dynamodb-cache
- Owner: xncbf
- License: mit
- Created: 2022-02-11T02:00:21.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-01-28T12:32:24.000Z (about 2 years ago)
- Last Synced: 2025-06-06T00:14:42.406Z (10 months ago)
- Topics: aws, cache, django, python, serverless
- Language: Python
- Homepage: https://pypi.org/project/django-dynamodb-cache/
- Size: 71.3 KB
- Stars: 32
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# django-dynamodb-cache
Fast, safe, cost-effective DynamoDB cache backend for Django
- [django-dynamodb-cache](#django-dynamodb-cache)
- [Introduce](#introduce)
- [Why should I use this?](#why-should-i-use-this)
- [Installation](#installation)
- [Setup on Django](#setup-on-django)
- [Aws credentials](#aws-credentials)
- [Create cache table command](#create-cache-table-command)
- [Future improvements](#future-improvements)
- [How to contribute](#how-to-contribute)
- [Debug](#debug)
## 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
```sh
pip install django-dynamodb-cache
```
## Setup on Django
On Django `settings.py`
```python
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.
## Create cache table command
Run manage command to create cache table on Dynamodb before using
```zsh
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
```