Skip to main content

Amazon Simple Storage Service (S3) cache backend for Django

Project description

About

This is Amazon Simple Storage Service (S3) cache backend for Django. It is based on the django.core.cache.backends.filebased.FileBasedCache backend and operates in similar fashion. This backend uses django-storages to read/write the date into S3. It uses the s3boto storage backend.

All key/values passed to this backend are stored in a flat directory structure in your S3 bucket. It uses sha1 instead of md5 to create the file name because it proved to be faster when I measured it.

Installation

Use pip to install from PyPI:

pip install django-s3-cache

Add s3cache to your settings.py file:

INSTALLED_APPS = (
    ...
    's3cache',
    ...
)

Configure the use of this backend:

CACHES = {
    'default': {
        'BACKEND': 's3cache.AmazonS3Cache',
        'OPTIONS': {
            'ACCESS_KEY_ID': 'Your AWS access key',
            'SECRET_ACCESS_KEY' : 'Your AWS secret access key',
            'STORAGE_BUCKET_NAME': 'Your AWS storage bucket name',
        }
    }
}

Configuration

Django S3 Cache supports many configuration options. They should be defined as keys of the OPTIONS dictionary in settings.py as shown abowe. For a full list take a look at the code. If something is not defined explicitly it follows the defaults of s3boto backend from django-storages which in turn reads them from settings.py.

NB: some values in settings.py may be used globally by boto and other AWS aware Django components since they follow the format AWS_XXXX. It’s always best to define your values as cache options explicitly if you don’t want to run into problems.

Some notable options are:

  • LOCATION - the directory prefix under which to store cache files. Defaults to empty string, which means the root directory;

  • DEFAULT_ACL == private - default ACL for created objects. Unlike the s3boto storage backend we set this to private;

  • BUCKET_ACL == DEFAULT_ACL - ACL for the bucket if auto created. By default set to private. It’s best to use separate bucket for cache files;

  • REDUCED_REDUNDANCY - set to True if you want to save a few cents on storage costs;

  • IS_GZIPPED - set to True to enable Gzip compression. Used together with GZIP_CONTENT_TYPES. See django-storages documentation.

Django S3 implements culling strategy similar to the stock filesystem backend. It will honor the following options:

  • MAX_ENTRIES - the maximum number of entries allowed in the cache before old values are deleted. This argument defaults to 300;

  • CULL_FREQUENCY - the fraction of entries that are culled when MAX_ENTRIES is reached. The actual ratio is 1/CULL_FREQUENCY, so set CULL_FREQUENCY to 2 to cull half of the entries when MAX_ENTRIES is reached;

Contibuting

Source code and issue tracker are at https://github.com/atodorov/django-s3-cache

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-s3-cache-0.1.tar.gz (4.9 kB view details)

Uploaded Source

File details

Details for the file django-s3-cache-0.1.tar.gz.

File metadata

File hashes

Hashes for django-s3-cache-0.1.tar.gz
Algorithm Hash digest
SHA256 53511a1df02ae4433f02a976d2a97c3bfadca8bf3929d9b3b3fdccbf23af4a60
MD5 6c3500491c4ca03a2e119c67e6658ce8
BLAKE2b-256 9fbc4e66c59d78d58ac3e5bae263526af4e8a96a96b5cf83d42516cdde8ef499

See more details on using hashes here.

Supported by

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