1
0
Fork 0

Merge pull request #135 from satnogs/redis

Redis cache support
pull/137/merge
Nikos Roussos 2017-02-21 18:39:00 +02:00 committed by GitHub
commit 97e7d44342
12 changed files with 45 additions and 20 deletions

View File

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

View File

@ -5,6 +5,7 @@ RUN yum -y install python python-pip python-devel git gcc libjpeg-turbo-devel \
libxml2-devel libxslt-devel mysql-devel mysql npm
RUN yum -y clean all
RUN npm install -g bower
RUN pip install --upgrade pip
COPY ./requirements/ /tmp/requirements/
RUN pip install -r /tmp/requirements/docker.txt

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

@ -19,4 +19,4 @@ web:
- ALLOWED_HOSTS=*
- DATABASE_URL=mysql://satnogsdb:satnogsdb@db/satnogsdb
command:
./docker/run-compose.sh
./docker/run-docker.sh

View File

@ -1,5 +0,0 @@
#!/bin/bash
find ./staticfiles -mindepth 1 -not -name '.gitkeep'| xargs rm -rf
./manage.py collectstatic --noinput
./manage.py migrate --noinput

View File

@ -1,4 +0,0 @@
#!/bin/sh
./docker/run-common.sh
./manage.py runserver 0.0.0.0:8000

View File

@ -1,4 +1,7 @@
#!/bin/sh
#!/bin/bash
./docker/run-common.sh
gunicorn db.wsgi:application -b 0.0.0.0:80 -w 2 --log-file -
find ./staticfiles -mindepth 1 -not -name '.gitkeep'| xargs rm -rf
bower install
./manage.py collectstatic --noinput
./manage.py migrate --noinput
./manage.py runserver 0.0.0.0:8000

View File

@ -1,17 +1,21 @@
# Basic stuff
django==1.10.5
django-shortuuidfield==0.1.3
django-compressor==2.1
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
opbeat==3.5.2
# Security
django-braces==1.10.0
django-braces==1.11.0
django-secure==1.0.1
# Users
@ -22,8 +26,8 @@ django-crispy-forms==1.6.1
Pillow==4.0.0
# API
djangorestframework==3.5.3
markdown==2.6.7
djangorestframework==3.5.4
markdown==2.6.8
django-filter==1.0.1
# Astronomy

View File

@ -3,4 +3,4 @@
# Debug & Testing
factory-boy==2.8.1
flake8==3.2.1
flake8==3.3.0