Lets say I have two apps in my Django website one for the API and one for the html pages, all urls starting with /api/ are handled by the API app. I have setup two caches with a specific setup for each like so:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
'LOCATION': 'page_cache',
'TIMEOUT': 7200,
'OPTIONS': {
'MAX_ENTRIES': 300,
}
},
'api': {
'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
'LOCATION': 'api_cache',
'TIMEOUT': 3600,
'OPTIONS': {
'MAX_ENTRIES': 3000,
}
}
}
How would I setup so that all requests to the API use the 'api' cache and all other requests use the 'default' cache?
I know I can use the cache_page function/decorator in the 'api' apps urls or views but I have a lot of urls and views so this would be annoying to maintain if I wanted to alter the timeout for instance.
I am also aware that I could just customise the middleware to point to a different cache when the request starts with '/api/' but is there no cleaner way of doing this?