Commit f0d9bd5e by Zia Fazal

data is not being cached in celery task

parent 8a78c055
"""
This file contains celery tasks for api_manager courses
"""
import sys
from celery.task import task # pylint: disable=import-error,no-name-in-module
from django.conf import settings
from django.core.cache import cache
@task(name=u'lms.djangoapps.api_manager.courses.tasks.cache_static_tab_content')
def cache_static_tab_contents(cache_key, contents):
"""
Caches course static tab contents.
"""
cache_expiration = getattr(settings, 'STATIC_TAB_CONTENTS_CACHE_TTL', 60 * 5)
contents_max_size_limit = getattr(settings, 'STATIC_TAB_CONTENTS_CACHE_MAX_SIZE_LIMIT', 4000)
if not sys.getsizeof(contents) > contents_max_size_limit:
cache.set(cache_key, contents, cache_expiration)
""" API implementation for course-oriented interactions. """ """ API implementation for course-oriented interactions. """
import sys
from collections import OrderedDict from collections import OrderedDict
import logging import logging
import itertools import itertools
...@@ -53,7 +54,6 @@ from api_manager.users.serializers import UserSerializer, UserCountByCitySeriali ...@@ -53,7 +54,6 @@ from api_manager.users.serializers import UserSerializer, UserCountByCitySeriali
from api_manager.utils import generate_base_uri, str2bool, get_time_series_data, parse_datetime from api_manager.utils import generate_base_uri, str2bool, get_time_series_data, parse_datetime
from .serializers import CourseSerializer from .serializers import CourseSerializer
from .serializers import GradeSerializer, CourseLeadersSerializer, CourseCompletionsLeadersSerializer from .serializers import GradeSerializer, CourseLeadersSerializer, CourseCompletionsLeadersSerializer
from .tasks import cache_static_tab_contents
from progress.serializers import CourseModuleCompletionSerializer from progress.serializers import CourseModuleCompletionSerializer
...@@ -383,11 +383,22 @@ def _get_static_tab_contents(request, course, tab): ...@@ -383,11 +383,22 @@ def _get_static_tab_contents(request, course, tab):
contents = cache.get(cache_key) contents = cache.get(cache_key)
if contents is None: if contents is None:
contents = get_static_tab_contents(request, course, tab, wrap_xmodule_display=False) contents = get_static_tab_contents(request, course, tab, wrap_xmodule_display=False)
cache_static_tab_contents.delay(cache_key, contents) _cache_static_tab_contents(cache_key, contents)
return contents return contents
def _cache_static_tab_contents(cache_key, contents):
"""
Caches course static tab contents.
"""
cache_expiration = getattr(settings, 'STATIC_TAB_CONTENTS_CACHE_TTL', 60 * 5)
contents_max_size_limit = getattr(settings, 'STATIC_TAB_CONTENTS_CACHE_MAX_SIZE_LIMIT', 4000)
if not sys.getsizeof(contents) > contents_max_size_limit:
cache.set(cache_key, contents, cache_expiration)
class CourseContentList(SecureAPIView): class CourseContentList(SecureAPIView):
""" """
**Use Case** **Use Case**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment