Skip to content

Commit

Permalink
memcached by default, database cache as backup; introducing new cache…
Browse files Browse the repository at this point in the history
… for course api
  • Loading branch information
maximz committed Mar 31, 2016
1 parent 7e9aaf6 commit 9abd892
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
2 changes: 2 additions & 0 deletions course_selection/management/commands/clear_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ def handle(self, *args, **kwargs):
self.stdout.write('Your default cache has been cleared!\n')
caches['courses'].clear()
self.stdout.write('Your courses cache has been cleared!\n')
caches['courseapi'].clear()
self.stdout.write('Your courseapi cache has been cleared!\n')
except AttributeError:
raise CommandError('You have no cache configured!\n')
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ def handle(self, *args, **options):
data = json.dumps(results)
caches['courses'].set(term_code, data)
self.stdout.write('course selection: cache regenerated for term ' + str(term_code))
caches['courseapi'].clear()
self.stdout.write('course selection: courseapi cache cleared.')
2 changes: 1 addition & 1 deletion course_selection/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def get_users_json(request):


@require_GET
@cache_page(60 * 30) # cache for 30 minutes
@cache_page(60 * 30, cache="courseapi") # cache for 30 minutes
def get_courses_json(request, term_code):
"""
Returns list of courses for a semester
Expand Down
3 changes: 3 additions & 0 deletions settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@
'courses': {
'BACKEND': 'django.core.cache.backends.dummy.DummyCache', # overwritten in prod.py
},
'courseapi': {
'BACKEND': 'django.core.cache.backends.dummy.DummyCache', # overwritten in prod.py
},
'resources': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'TIMEOUT': 60
Expand Down
26 changes: 17 additions & 9 deletions settings/prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ def get_cache():
'MEMCACHIER_SERVERS'].replace(',', ';')
environ['MEMCACHE_USERNAME'] = environ['MEMCACHIER_USERNAME']
environ['MEMCACHE_PASSWORD'] = environ['MEMCACHIER_PASSWORD']
return {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'
},
'courses': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'
},
'courseapi': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'
}
}
except:
return {
'default': {
'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
Expand All @@ -53,6 +65,11 @@ def get_cache():
'LOCATION': 'courses_cache_table',
'TIMEOUT': 60 * 60
},
'courseapi': {
'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
'LOCATION': 'courseapi_cache_table',
'TIMEOUT': 60 * 60
},
'memcache': {
'BACKEND': 'django_pylibmc.memcached.PyLibMCCache',
'TIMEOUT': 500,
Expand All @@ -62,15 +79,6 @@ def get_cache():
}
}
}
except:
return {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'
},
'courses': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'
}
}

CACHES = get_cache()

Expand Down

0 comments on commit 9abd892

Please sign in to comment.