Skip to content

Commit 01d70a8

Browse files
author
Miguel Leon
authored
Merge pull request #156 from lsetiawan/apply_redis
Added the use of Redis to cache get features result
2 parents 8fba446 + ef466fa commit 01d70a8

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ psycopg2
1212
requests
1313
django-recaptcha
1414
pyyaml
15-
xlrd
15+
xlrd
16+
django-redis

templatesAndSettings/settings/base.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,19 @@
261261
style_class="awesome-marker-icon-cadetblue")
262262
}
263263
""" END SAMPLING FEATURE TYPE LEGEND MAPPING """
264+
265+
""" REDIS CACHING CONFIGURATION """
266+
CACHES = {
267+
"default": {
268+
"BACKEND": "django_redis.cache.RedisCache",
269+
"LOCATION": "redis://127.0.0.1:6379/1",
270+
"OPTIONS": {
271+
"CLIENT_CLASS": "django_redis.client.DefaultClient"
272+
},
273+
"KEY_PREFIX": "odm2admin"
274+
}
275+
}
276+
277+
# Cache time to live is 15 minutes.
278+
CACHE_TTL = 60 * 15
279+
""" END REDIS CACHING CONFIGURATION"""

templatesAndSettings/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from django.contrib import admin
55
from django.http.response import HttpResponseRedirect
66
from django.conf.urls.static import static
7+
from django.views.decorators.cache import cache_page
78

89
# from ODM2CZOData import views # How can I use config file for this??
910
import importlib
@@ -159,7 +160,7 @@
159160
url(r'^' + 'publications.html', views.publications,
160161
name="publications"),
161162
url(r'^' + 'features/type=(?P<sf_type>([\w\s]+,?)+)&'
162-
'datasets=(?P<ds_ids>([a-zA-Z]+)?(([0-9]+,?)+)?)', views.get_features),
163+
'datasets=(?P<ds_ids>([a-zA-Z]+)?(([0-9]+,?)+)?)', cache_page(settings.CACHE_TTL)(views.get_features)),
163164
# url(r'^' + 'pubview/citationid=(?P<citationid>(\d+))/$',
164165
# views.add_pub,
165166
# name="add_pub"),

0 commit comments

Comments
 (0)