Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal cache implementation #155

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions coptic/coptic/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,16 @@
'mod_wsgi.server'
)

MIDDLEWARE_CLASSES = [
MIDDLEWARE = [
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.cache.UpdateCacheMiddleware',
'django.middleware.cache.FetchFromCacheMiddleware',
]
if django.VERSION[0] < 2:
MIDDLEWARE_CLASSES.append('django.contrib.auth.middleware.SessionAuthenticationMiddleware')
MIDDLEWARE = MIDDLEWARE_CLASSES # for django >= 1.10


# for newer django
TEMPLATES = [
Expand All @@ -61,11 +59,6 @@
}
]

# for older django
TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.request",
"django.contrib.auth.context_processors.auth"
)

ROOT_URLCONF = 'coptic.urls'

Expand Down Expand Up @@ -105,6 +98,13 @@
},
}
}
# Cache configuration
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
'LOCATION': '/tmp/django_cache',
}
}

# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/
Expand Down
9 changes: 6 additions & 3 deletions coptic/coptic/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from django.db.models import Q, Case, When, IntegerField, F
from django.shortcuts import render, get_object_or_404, redirect
from django.db.models.functions import Lower
from django.views.decorators.cache import cache_page
from django.core.cache import cache
from texts.search_fields import get_search_fields
from coptic.settings.base import DEPRECATED_URNS
from collections import OrderedDict
Expand All @@ -19,12 +21,13 @@
def keyvalue(dict, key):
return dict.get(key)

@cache_page(60 * 15)
def home_view(request):
'Home'
context = _base_context()
return render(request, 'home.html', context)


@cache_page(60 * 15)
def corpus_view(request, corpus=None):
corpus_object = get_object_or_404(models.Corpus, slug=corpus)

Expand Down Expand Up @@ -64,7 +67,7 @@ def corpus_view(request, corpus=None):
})
return render(request, 'corpus.html', context)


@cache_page(60 * 15)
def text_view(request, corpus=None, text=None, format=None):
text_object = get_object_or_404(models.Text, slug=text)
if not format:
Expand Down Expand Up @@ -157,7 +160,7 @@ def get_meta_values(meta):
meta_values = [re.sub(HTML_TAG_REGEX, '', meta_value) for meta_value in meta_values]
return meta_values


@cache_page(60 * 15)
def index_view(request, special_meta=None):
context = _base_context()

Expand Down