mirror of
https://github.com/PokeAPI/pokeapi
synced 2024-11-21 19:03:08 +00:00
Set up redis cache (#176)
This commit is contained in:
parent
422d98fff2
commit
eb5783697b
5 changed files with 34 additions and 10 deletions
3
Makefile
3
Makefile
|
@ -22,3 +22,6 @@ test:
|
|||
|
||||
clean:
|
||||
rm -rf *.pyc
|
||||
|
||||
migrate:
|
||||
python manage.py migrate --settings=config.local
|
||||
|
|
|
@ -7,5 +7,11 @@ DATABASES = {
|
|||
}
|
||||
}
|
||||
|
||||
CACHES = {
|
||||
'default': {
|
||||
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
|
||||
}
|
||||
}
|
||||
|
||||
DEBUG = True
|
||||
TASTYPIE_FULL_DEBUG = True
|
||||
|
|
|
@ -100,10 +100,13 @@ DATABASES = {
|
|||
}
|
||||
|
||||
CACHES = {
|
||||
'default': {
|
||||
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
|
||||
'TIMEOUT': 30
|
||||
},
|
||||
"default": {
|
||||
"BACKEND": "django_redis.cache.RedisCache",
|
||||
"LOCATION": "redis://127.0.0.1:6379/1",
|
||||
"OPTIONS": {
|
||||
"CLIENT_CLASS": "django_redis.client.DefaultClient",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SECRET_KEY = os.environ.get(
|
||||
|
@ -127,7 +130,8 @@ INSTALLED_APPS = (
|
|||
'django.contrib.humanize',
|
||||
'corsheaders',
|
||||
'rest_framework',
|
||||
'markdown_deux'
|
||||
'markdown_deux',
|
||||
'cachalot'
|
||||
) + CUSTOM_APPS
|
||||
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
from django.shortcuts import render_to_response, redirect
|
||||
from django.template import RequestContext
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
@ -13,9 +14,15 @@ import stripe
|
|||
|
||||
def about(request):
|
||||
|
||||
total_views = ResourceView.objects.total_count()
|
||||
total_views = cache.get('total_views')
|
||||
if total_views:
|
||||
total_views = ResourceView.objects.total_count()
|
||||
cache.set('total_views', total_views)
|
||||
|
||||
average_day = int(round(total_views / ResourceView.objects.count()))
|
||||
average_day = cache.get('average_day')
|
||||
if average_day:
|
||||
average_day = int(round(total_views / ResourceView.objects.count()))
|
||||
cache.set('average_day')
|
||||
|
||||
return render_to_response(
|
||||
'pages/about.html',
|
||||
|
@ -29,9 +36,11 @@ def about(request):
|
|||
|
||||
def home(request):
|
||||
|
||||
total_views = ResourceView.objects.total_count()
|
||||
|
||||
total_views = int(round(total_views, -2))
|
||||
total_views = cache.get('total_views')
|
||||
if total_views:
|
||||
total_views = ResourceView.objects.total_count()
|
||||
total_views = int(round(total_views, -2))
|
||||
cache.set('total_views', total_views)
|
||||
|
||||
stripe_key = settings.STRIPE_KEYS['publishable']
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@ dj-stripe==0.3.5
|
|||
django-cors-headers==1.0.0
|
||||
django-discover-runner==0.4
|
||||
django-imagekit==3.2.4
|
||||
django-redis==4.4.0
|
||||
django-cachalot==1.2.1
|
||||
django-tastypie==0.12.1
|
||||
django-markdown-deux==1.0.5
|
||||
djangorestframework>=3.1.0
|
||||
|
|
Loading…
Reference in a new issue