Skip to content

nebolsin/django-cache-url

 
 

Repository files navigation

Django-Cache-URL

image

This simple Django utility allows you to utilize the 12factor inspired CACHE_URL environment variable to configure your Django application.

This was built with inspiration from rdegges' django-heroku-memcacheify as a way to use CACHE_URL in apps that aren't necessarily hosted on Heroku.

The internals borrow heavily from kennethreitz's dj-database-url.

Supported caches

Support currently exists for Local-memory, database, file, memcached (including pymemcached and djangopylibmc), redis (including hiredis).

Installation

Installation is simple too:

$ pip install django-cache-url

Usage

Configure your cache in settings.py from CACHE_URL:

CACHES = {'default': django_cache_url.config()}

Defaults to local memory cache if CACHE_URL isn't set.

Parse an arbitrary Cache URL:

CACHES = {'default': django_cache_url.parse('memcache://...')}

URL schema

  • locmem (default): 'locmem://[NAME]'
  • db: 'db://TABLE_NAME'
  • dummy: 'dummy://'
  • file: 'file:///PATH/TO/FILE'
  • memcached: 'memcached://HOST:PORT'1
  • pymemcached: 'pymemcached://HOST:PORT' For use with the python-memcached library. Useful if you're using Ubuntu <= 10.04.
  • djangopylibmc: 'djangopylibmc://HOST:PORT' For use with SASL based setups such as Heroku.
  • redis: 'redis://[USER:PASSWORD@]HOST:PORT[:DB]' or 'redis:///PATH/TO/SOCKET[:DB]' For use with django-redis.
  • hiredis 'hiredis://[USER:PASSWORD@]HOST:PORT[:DB]' or 'hiredis:///PATH/TO/SOCKET[:DB]' For use with django-redis library using HiredisParser.

All cache urls support optional cache arguments by using a query string, e.g.: 'memcached://HOST:PORT?key_prefix=site1'. See the Django cache arguments documentation.


  1. To specify multiple instances, separate the the HOST:PORT pair by commas, e.g: 'memcached://HOST1:PORT1,HOST2:PORT2`

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%