1
0
Fork 0

Add redis support

merge-requests/135/head
Nikos Roussos 2017-02-21 17:54:07 +02:00
parent 4d1b4cfaec
commit 1e4f34fd97
No known key found for this signature in database
GPG Key ID: BADFF1767BA7C8E1
6 changed files with 32 additions and 2 deletions

View File

@ -1,2 +0,0 @@
db/static/js/lib/
staticfiles/

View File

@ -11,6 +11,7 @@ from django.http import HttpResponseNotFound, HttpResponseServerError, HttpRespo
from django.conf import settings
from django.contrib.sites.shortcuts import get_current_site
from django.template.loader import render_to_string
from django.views.decorators.cache import cache_page
from db.base.models import Mode, Transmitter, Satellite, Suggestion
from db.base.forms import SuggestionForm
@ -18,6 +19,7 @@ from db.base.forms import SuggestionForm
logger = logging.getLogger('db')
@cache_page(settings.CACHE_TTL)
def home(request):
"""View to render home page."""
satellites = Satellite.objects.all()
@ -131,6 +133,7 @@ def stats(request):
return render(request, 'base/stats.html')
@cache_page(settings.CACHE_TTL)
def statistics(request):
"""View to create statistics endpoint."""
satellites = Satellite.objects.all()

View File

@ -57,6 +57,7 @@ CACHES = {
'LOCATION': 'unique-snowflake'
}
}
CACHE_TTL = getenv('CACHE_TTL', 300)
# Internationalization
TIME_ZONE = 'UTC'

View File

@ -12,6 +12,18 @@ INSTALLED_APPS = INSTALLED_APPS + (
'opbeat.contrib.django',
)
# Cache
CACHES = {
'default': {
'BACKEND': 'redis_cache.RedisCache',
'LOCATION': 'unix:/var/run/redis/redis.sock',
'OPTIONS': {
'CLIENT_CLASS': 'django_redis.client.DefaultClient'
},
'KEY_PREFIX': 'db-{0}'.format(ENVIRONMENT)
}
}
# Security
SECURE_HSTS_SECONDS = 60
SECURE_HSTS_INCLUDE_SUBDOMAINS = True

View File

@ -12,6 +12,18 @@ INSTALLED_APPS = INSTALLED_APPS + (
'opbeat.contrib.django',
)
# Cache
CACHES = {
'default': {
'BACKEND': 'redis_cache.RedisCache',
'LOCATION': 'unix:/var/run/redis/redis.sock',
'OPTIONS': {
'CLIENT_CLASS': 'django_redis.client.DefaultClient'
},
'KEY_PREFIX': 'db-{0}'.format(ENVIRONMENT)
}
}
# Security
ALLOWED_HOSTS = [
os.getenv('ALLOWED_HOSTS', '*')

View File

@ -5,6 +5,10 @@ django-compressor==2.1.1
django-jsonfield==1.0.1
django-bower==5.2.0
# Cache
redis==2.10.5
django-redis-cache==1.7.1
# Configuration
django-dotenv==1.4.1
dj-database-url==0.4.2