Idea of the day: dj-cache-url

Idea of the day: dj-cache-url

Published Sept. 1, 2016 in Development - Last update on Sept. 1, 2016.

I was working in a Django project, more precisely its settings, I stopped in front of CACHES parameter, I love when code use an agnostic way and in Django settings I love to use dj-database-url to configure DATABASES, so I made the same for CACHES: At this time dj-cache-url was born.

dj-database-url ?

I won't give you all the story, but dj-database-url is small Python module helping to create a Django database configuration. Its usage is quite simple:

  1. You set up the DATABASE_URL environmental variable with for example: export DATABASE_URL=postgres://myserver:5431/mydb
  2. You put DATABASES = {'default':  dj_database_url.config()} in your settings.py

It is done, you have a full PostgreSQL configuration that you can edit easily. Very very useful for testing purpose or pass from dev to production. Added to this, the avaibility of controls backends specific options like default DB, user, password, etc...

And dj-cache-url ?

The same:

  1. You set up the CACHE_URL environmental variable with for example: export CACHE_URL=memcached://127.0.0.1:11211
  2. You put CACHES = {'default':  dj_cache_url.config()} in your settings.py

And you have Memcached config. dj-database-url is pretty simple, a single file. I just fork it and adapt to my needs. It support the following backends:

  • Memcached
  • File system
  • locmem
  • Dummy
  • Redis (with django-redis)

References

Comments

No comments yet.

Post your comment

Comment as . Log out.