Skip to content

not-gitmodules/notgitmodules-django-redis-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Redis-based cache for Django

Usage

  1. Install this not_gitmodule using our brand tool, or gitmodules.
  2. Add the containing of requirements.txt to your requirements.txt file, and rerun pip install -r requirements.txt. (if not yet done)
  3. Add redis_cache to your INSTALLED_APPS in your Django settings file.

Example settings.py:

  1. Add the following to your settings.py file's imports:
from django.core.cache import cache # this is the default cache designed for Django
from cache.cache import Cache # this is this module with cache interface
  1. Add caching to your project
CACHES = {
    'default': {
        'BACKEND': 'django_redis.cache.RedisCache',
        'LOCATION': 'redis://127.0.0.1:6379/1',
        'OPTIONS': {
            'CLIENT_CLASS': 'django_redis.client.DefaultClient',
            'CONNECTION_POOL_KWARGS': {
                'max_connections': 100,
                'retry_on_timeout': True,
            }
        }
    }
}
  1. Use the cache in your project
from django.conf import settings

REDIS_CACHE = settings.CACHE
  1. Example usage:
def find_entry(some_id):
    if not (entry := REDIS_CACHE.get_instance(some_id)):
        try:
            entry: list = SomeModel.objects.get(id=some_id)
        except SomeModel.DoesNotExist:
            return {"status": False, "message": "Entry not found"}
    return {"status": True, "data": entry}

Installation with not_gitmodules

  • Example of notgitmodules.yaml:
utils:
  django_redis_cache: https://github.com/not-gitmodules/notgitmodules-django-redis-cache
  • Run the following command:
not_gitmodules -y path/to/notgitmodules.yaml

About

Simple Redis-based cache for Django

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages