- Install this
not_gitmoduleusing our brand tool, or gitmodules. - Add the containing of
requirements.txtto yourrequirements.txtfile, and rerunpip install -r requirements.txt. (if not yet done) - Add
redis_cacheto yourINSTALLED_APPSin your Django settings file.
Example settings.py:
- Add the following to your
settings.pyfile'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- 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,
}
}
}
}- Use the cache in your project
from django.conf import settings
REDIS_CACHE = settings.CACHE- 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}- 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