mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
change cacheing to use cacheops
This commit is contained in:
@@ -31,6 +31,7 @@ REDIS = {
|
||||
'PORT': 6379,
|
||||
'PASSWORD': '',
|
||||
'DATABASE': 0,
|
||||
'CACHE_DATABASE': 1,
|
||||
'DEFAULT_TIMEOUT': 300,
|
||||
'SSL': False,
|
||||
}
|
||||
@@ -60,16 +61,7 @@ BANNER_LOGIN = ''
|
||||
# BASE_PATH = 'netbox/'
|
||||
BASE_PATH = ''
|
||||
|
||||
# The fraction of entries that are culled when CACHE_MAX_ENTRIES is reached. The actual ratio is 1 / CACHE_CULL_FREQUENCY,
|
||||
# so set CACHE_CULL_FREQUENCY to 2 to cull half the entries when CACHE_MAX_ENTRIES is reached. This setting should be an
|
||||
# integer and defaults to 3
|
||||
CACHE_CULL_FREQUENCY = 3
|
||||
|
||||
# Max number of entries (unique pages) to store in the cache at a time.
|
||||
CACHE_MAX_ENTRIES = 300
|
||||
|
||||
# Cache timeout in seconds. Set to `None` to enforce an infinate timeout. Set to 0 to dissable caching by immediatly
|
||||
# expiring keys. Defaults to 900 (15 minutes)
|
||||
# Cache timeout in seconds. Set to 0 to dissable caching. Defaults to 900 (15 minutes)
|
||||
CACHE_TIMEOUT = 900
|
||||
|
||||
# Maximum number of days to retain logged changes. Set to 0 to retain changes indefinitely. (Default: 90)
|
||||
|
@@ -138,6 +138,7 @@ REDIS_HOST = REDIS.get('HOST', 'localhost')
|
||||
REDIS_PORT = REDIS.get('PORT', 6379)
|
||||
REDIS_PASSWORD = REDIS.get('PASSWORD', '')
|
||||
REDIS_DATABASE = REDIS.get('DATABASE', 0)
|
||||
REDIS_CACHE_DATABASE = REDIS.get('CACHE_DATABASE', 1)
|
||||
REDIS_DEFAULT_TIMEOUT = REDIS.get('DEFAULT_TIMEOUT', 300)
|
||||
REDIS_SSL = REDIS.get('SSL', False)
|
||||
|
||||
@@ -159,8 +160,8 @@ INSTALLED_APPS = [
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'django.contrib.humanize',
|
||||
'cacheops',
|
||||
'corsheaders',
|
||||
'django_redis',
|
||||
'debug_toolbar',
|
||||
'django_filters',
|
||||
'django_tables2',
|
||||
@@ -231,21 +232,30 @@ else:
|
||||
if REDIS_PASSWORD:
|
||||
REDIS_CACHE_CON_STRING = '{}@{}'.format(REDIS_PASSWORD, REDIS_CACHE_CON_STRING)
|
||||
|
||||
REDIS_CACHE_CON_STRING = '{}{}:{}/{}'.format(REDIS_CACHE_CON_STRING, REDIS_HOST, REDIS_PORT, REDIS_DATABASE)
|
||||
CACHE_BACKEND = 'django_redis.cache.RedisCache'
|
||||
REDIS_CACHE_CON_STRING = '{}{}:{}/{}'.format(REDIS_CACHE_CON_STRING, REDIS_HOST, REDIS_PORT, REDIS_CACHE_DATABASE)
|
||||
|
||||
CACHES = {
|
||||
"default": {
|
||||
"BACKEND": CACHE_BACKEND,
|
||||
"LOCATION": REDIS_CACHE_CON_STRING,
|
||||
'TIMEOUT': CACHE_TIMEOUT,
|
||||
"OPTIONS": {
|
||||
"CLIENT_CLASS": "django_redis.client.DefaultClient",
|
||||
"MAX_ENTRIES": CACHE_MAX_ENTRIES,
|
||||
"CULL_FREQUENCY": CACHE_CULL_FREQUENCY
|
||||
}
|
||||
}
|
||||
if not CACHE_TIMEOUT:
|
||||
CACHEOPS_ENABLED = False
|
||||
else:
|
||||
CACHEOPS_ENABLED = True
|
||||
|
||||
CACHEOPS_REDIS = REDIS_CACHE_CON_STRING
|
||||
CACHEOPS_DEFAULTS = {
|
||||
'timeout': CACHE_TIMEOUT
|
||||
}
|
||||
CACHEOPS = {
|
||||
'auth.user': {'ops': 'get', 'timeout': 60*15},
|
||||
'auth.*': {'ops': ('fetch', 'get')},
|
||||
'auth.permission': {'ops': 'all'},
|
||||
'dcim.*': {'ops': 'all'},
|
||||
'ipam.*': {'ops': 'all'},
|
||||
'extras.*': {'ops': 'all'},
|
||||
'secrets.*': {'ops': 'all'},
|
||||
'users.*': {'ops': 'all'},
|
||||
'tenancy.*': {'ops': 'all'},
|
||||
'virtualization.*': {'ops': 'all'},
|
||||
}
|
||||
CACHEOPS_DEGRADE_ON_FAILURE = True
|
||||
|
||||
# WSGI
|
||||
WSGI_APPLICATION = 'netbox.wsgi.application'
|
||||
|
@@ -163,7 +163,6 @@ SEARCH_TYPES = OrderedDict((
|
||||
class HomeView(View):
|
||||
template_name = 'home.html'
|
||||
|
||||
@method_decorator(cache_page(settings.CACHE_TIMEOUT))
|
||||
def get(self, request):
|
||||
|
||||
connected_consoleports = ConsolePort.objects.filter(
|
||||
@@ -223,7 +222,6 @@ class HomeView(View):
|
||||
|
||||
class SearchView(View):
|
||||
|
||||
@method_decorator(cache_page(settings.CACHE_TIMEOUT))
|
||||
def get(self, request):
|
||||
|
||||
# No query
|
||||
@@ -277,7 +275,6 @@ class APIRootView(APIView):
|
||||
def get_view_name(self):
|
||||
return "API Root"
|
||||
|
||||
@method_decorator(cache_page(settings.CACHE_TIMEOUT))
|
||||
def get(self, request, format=None):
|
||||
|
||||
return Response(OrderedDict((
|
||||
|
Reference in New Issue
Block a user