diff --git a/cms/djangoapps/contentstore/config/tests/utils.py b/cms/djangoapps/contentstore/config/tests/utils.py index 69430ccb1d..af5295e3b5 100644 --- a/cms/djangoapps/contentstore/config/tests/utils.py +++ b/cms/djangoapps/contentstore/config/tests/utils.py @@ -5,7 +5,7 @@ to configure flags related to persistent grading. from contextlib import contextmanager from contentstore.config.models import NewAssetsPageFlag, CourseNewAssetsPageFlag -from request_cache.middleware import RequestCache +from openedx.core.djangoapps.request_cache.middleware import RequestCache @contextmanager diff --git a/cms/djangoapps/xblock_config/models.py b/cms/djangoapps/xblock_config/models.py index 92d932c864..760425e69e 100644 --- a/cms/djangoapps/xblock_config/models.py +++ b/cms/djangoapps/xblock_config/models.py @@ -9,7 +9,7 @@ from config_models.models import ConfigurationModel from django.db.models import TextField from openedx.core.djangoapps.xmodule_django.models import CourseKeyField -from request_cache.middleware import request_cached +from openedx.core.djangoapps.request_cache.middleware import request_cached class StudioConfig(ConfigurationModel): diff --git a/cms/djangoapps/xblock_config/tests/test_models.py b/cms/djangoapps/xblock_config/tests/test_models.py index 163e078599..3ce81a51f1 100644 --- a/cms/djangoapps/xblock_config/tests/test_models.py +++ b/cms/djangoapps/xblock_config/tests/test_models.py @@ -7,7 +7,7 @@ import ddt from django.test import TestCase from opaque_keys.edx.locator import CourseLocator -from request_cache.middleware import RequestCache +from openedx.core.djangoapps.request_cache.middleware import RequestCache from xblock_config.models import CourseEditLTIFieldsEnabledFlag diff --git a/cms/envs/common.py b/cms/envs/common.py index 0536b3581c..7fd25d9c04 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -457,7 +457,7 @@ else: MIDDLEWARE_CLASSES = [ 'crum.CurrentRequestUserMiddleware', - 'request_cache.middleware.RequestCache', + 'openedx.core.djangoapps.request_cache.middleware.RequestCache', 'openedx.core.djangoapps.monitoring_utils.middleware.MonitoringMemoryMiddleware', diff --git a/common/djangoapps/course_modes/models.py b/common/djangoapps/course_modes/models.py index 3105f1c050..62edaa074d 100644 --- a/common/djangoapps/course_modes/models.py +++ b/common/djangoapps/course_modes/models.py @@ -17,7 +17,7 @@ from openedx.core.djangoapps.content.course_overviews.models import CourseOvervi from opaque_keys.edx.keys import CourseKey from openedx.core.djangoapps.xmodule_django.models import CourseKeyField -from request_cache.middleware import RequestCache, ns_request_cached +from openedx.core.djangoapps.request_cache.middleware import RequestCache, ns_request_cached Mode = namedtuple('Mode', [ diff --git a/common/djangoapps/django_comment_common/utils.py b/common/djangoapps/django_comment_common/utils.py index 8a06ec0514..dcdd986a7b 100644 --- a/common/djangoapps/django_comment_common/utils.py +++ b/common/djangoapps/django_comment_common/utils.py @@ -11,7 +11,7 @@ from django_comment_common.models import ( Role ) from openedx.core.djangoapps.course_groups.cohorts import get_legacy_discussion_settings -from request_cache.middleware import request_cached +from openedx.core.djangoapps.request_cache.middleware import request_cached from .models import CourseDiscussionSettings diff --git a/common/djangoapps/edxmako/paths.py b/common/djangoapps/edxmako/paths.py index e4ea566be9..c8b66e3ff6 100644 --- a/common/djangoapps/edxmako/paths.py +++ b/common/djangoapps/edxmako/paths.py @@ -11,7 +11,7 @@ from django.conf import settings from mako.exceptions import TopLevelLookupException from mako.lookup import TemplateLookup -from request_cache.middleware import request_cached +from openedx.core.djangoapps.request_cache.middleware import request_cached from openedx.core.djangoapps.theming.helpers import get_template as themed_template from openedx.core.djangoapps.theming.helpers import get_template_path_with_theme, strip_site_theme_templates_path diff --git a/common/djangoapps/edxmako/request_context.py b/common/djangoapps/edxmako/request_context.py index 71a7a42852..8daeac4698 100644 --- a/common/djangoapps/edxmako/request_context.py +++ b/common/djangoapps/edxmako/request_context.py @@ -22,7 +22,7 @@ Methods for creating RequestContext for using with Mako templates. from crum import get_current_request from django.template import RequestContext -import request_cache +from openedx.core.djangoapps.request_cache import get_cache from util.request import safe_get_host @@ -38,7 +38,7 @@ def get_template_request_context(request=None): if request is None: return None - request_cache_dict = request_cache.get_cache('edxmako') + request_cache_dict = get_cache('edxmako') cache_key = "request_context" if cache_key in request_cache_dict: return request_cache_dict[cache_key] diff --git a/common/djangoapps/edxmako/tests.py b/common/djangoapps/edxmako/tests.py index 44e0903954..6406b0f563 100644 --- a/common/djangoapps/edxmako/tests.py +++ b/common/djangoapps/edxmako/tests.py @@ -12,7 +12,7 @@ from mock import Mock, patch from edxmako import LOOKUP, add_lookup from edxmako.request_context import get_template_request_context from edxmako.shortcuts import is_any_marketing_link_set, is_marketing_link_set, marketing_link, render_to_string -from request_cache.middleware import RequestCache +from openedx.core.djangoapps.request_cache.middleware import RequestCache from student.tests.factories import UserFactory from util.testing import UrlResetMixin diff --git a/common/djangoapps/student/models.py b/common/djangoapps/student/models.py index 0ee6eb1480..07b13542f4 100644 --- a/common/djangoapps/student/models.py +++ b/common/djangoapps/student/models.py @@ -48,7 +48,6 @@ from slumber.exceptions import HttpClientError, HttpServerError import dogstats_wrapper as dog_stats_api import lms.lib.comment_client as cc -import request_cache from student.signals import UNENROLL_DONE, ENROLL_STATUS_CHANGE, ENROLLMENT_TRACK_UPDATED from lms.djangoapps.certificates.models import GeneratedCertificate from course_modes.models import CourseMode @@ -60,6 +59,7 @@ from courseware.models import ( from enrollment.api import _default_course_mode from openedx.core.djangoapps.content.course_overviews.models import CourseOverview +from openedx.core.djangoapps.request_cache import clear_cache, get_cache from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.xmodule_django.models import CourseKeyField, NoneToEmptyManager from track import contexts @@ -1870,7 +1870,7 @@ class CourseEnrollment(models.Model): """ # before populating the cache with another bulk set of data, # remove previously cached entries to keep memory usage low. - request_cache.clear_cache(cls.MODE_CACHE_NAMESPACE) + clear_cache(cls.MODE_CACHE_NAMESPACE) records = cls.objects.filter(user__in=users, course_id=course_key).select_related('user') cache = cls._get_mode_active_request_cache() @@ -1883,7 +1883,7 @@ class CourseEnrollment(models.Model): """ Returns the request-specific cache for CourseEnrollment """ - return request_cache.get_cache(cls.MODE_CACHE_NAMESPACE) + return get_cache(cls.MODE_CACHE_NAMESPACE) @classmethod def _get_enrollment_in_request_cache(cls, user, course_key): diff --git a/common/djangoapps/student/roles.py b/common/djangoapps/student/roles.py index 6a097a9320..ce91f79c33 100644 --- a/common/djangoapps/student/roles.py +++ b/common/djangoapps/student/roles.py @@ -10,7 +10,7 @@ from collections import defaultdict from django.contrib.auth.models import User from openedx.core.djangoapps.xmodule_django.models import CourseKeyField -from request_cache import get_cache +from openedx.core.djangoapps.request_cache import get_cache from student.models import CourseAccessRole log = logging.getLogger(__name__) diff --git a/common/djangoapps/track/event_transaction_utils.py b/common/djangoapps/track/event_transaction_utils.py index c81dde824c..53b86ddb3b 100644 --- a/common/djangoapps/track/event_transaction_utils.py +++ b/common/djangoapps/track/event_transaction_utils.py @@ -4,7 +4,7 @@ used in event tracking. """ from uuid import UUID, uuid4 -from request_cache import get_cache +from openedx.core.djangoapps.request_cache import get_cache def get_event_transaction_id(): diff --git a/common/djangoapps/util/db.py b/common/djangoapps/util/db.py index 340a50a5c4..585e711bed 100644 --- a/common/djangoapps/util/db.py +++ b/common/djangoapps/util/db.py @@ -9,7 +9,7 @@ from functools import wraps from django.db import DEFAULT_DB_ALIAS, DatabaseError, Error, transaction -import request_cache +from openedx.core.djangoapps.request_cache import get_cache OUTER_ATOMIC_CACHE_NAME = 'db.outer_atomic' @@ -160,7 +160,7 @@ def enable_named_outer_atomic(*names): if len(names) == 0: raise ValueError("At least one name must be specified.") - cache = request_cache.get_cache(OUTER_ATOMIC_CACHE_NAME) + cache = get_cache(OUTER_ATOMIC_CACHE_NAME) for name in names: cache[name] = True @@ -187,7 +187,7 @@ class OuterAtomic(transaction.Atomic): connection = transaction.get_connection(self.using) - cache = request_cache.get_cache(OUTER_ATOMIC_CACHE_NAME) + cache = get_cache(OUTER_ATOMIC_CACHE_NAME) # By default it is enabled. enable = True diff --git a/common/djangoapps/util/milestones_helpers.py b/common/djangoapps/util/milestones_helpers.py index f73d3bf208..df355b9a1c 100644 --- a/common/djangoapps/util/milestones_helpers.py +++ b/common/djangoapps/util/milestones_helpers.py @@ -11,7 +11,7 @@ from milestones.services import MilestonesService from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey -import request_cache +from openedx.core.djangoapps.request_cache import get_cache from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from xmodule.modulestore.django import modulestore @@ -359,7 +359,7 @@ def get_course_content_milestones(course_id, content_id=None, relationship='requ if user_id is None: return milestones_api.get_course_content_milestones(course_id, content_id, relationship) - request_cache_dict = request_cache.get_cache(REQUEST_CACHE_NAME) + request_cache_dict = get_cache(REQUEST_CACHE_NAME) if user_id not in request_cache_dict: request_cache_dict[user_id] = {} diff --git a/common/lib/xmodule/xmodule/modulestore/django.py b/common/lib/xmodule/xmodule/modulestore/django.py index f70e440ca2..2bdad9ffa2 100644 --- a/common/lib/xmodule/xmodule/modulestore/django.py +++ b/common/lib/xmodule/xmodule/modulestore/django.py @@ -24,19 +24,12 @@ import django.dispatch import django.utils from django.utils.translation import get_language, to_locale +from openedx.core.djangoapps.request_cache.middleware import RequestCache from xmodule.contentstore.django import contentstore from xmodule.modulestore.draft_and_published import BranchSettingMixin from xmodule.modulestore.mixed import MixedModuleStore from xmodule.util.django import get_current_request_hostname -try: - # We may not always have the request_cache module available - from request_cache.middleware import RequestCache - - HAS_REQUEST_CACHE = True -except ImportError: - HAS_REQUEST_CACHE = False - # We also may not always have the current request user (crum) module available try: from xblock_django.user_service import DjangoXBlockUserService @@ -256,10 +249,7 @@ def create_modulestore_instance( if key in _options and isinstance(_options[key], basestring): _options[key] = load_function(_options[key]) - if HAS_REQUEST_CACHE: - request_cache = RequestCache.get_request_cache() - else: - request_cache = None + request_cache = RequestCache.get_request_cache() try: metadata_inheritance_cache = caches['mongo_metadata_inheritance'] diff --git a/common/lib/xmodule/xmodule/video_module/video_module.py b/common/lib/xmodule/xmodule/video_module/video_module.py index 859fe03616..311c48c567 100644 --- a/common/lib/xmodule/xmodule/video_module/video_module.py +++ b/common/lib/xmodule/xmodule/video_module/video_module.py @@ -212,6 +212,7 @@ class VideoModule(VideoFields, VideoTranscriptsMixin, VideoStudentViewHandlers, return track_url, transcript_language, sorted_languages def get_html(self): + track_status = (self.download_track and self.track) transcript_download_format = self.transcript_download_format if not track_status else None sources = filter(None, self.html5_sources) diff --git a/lms/djangoapps/ccx/overrides.py b/lms/djangoapps/ccx/overrides.py index 9236418926..2320196c11 100644 --- a/lms/djangoapps/ccx/overrides.py +++ b/lms/djangoapps/ccx/overrides.py @@ -9,7 +9,7 @@ from ccx_keys.locator import CCXBlockUsageLocator, CCXLocator from django.db import transaction from opaque_keys.edx.keys import CourseKey, UsageKey -import request_cache +from openedx.core.djangoapps.request_cache import get_cache from courseware.field_overrides import FieldOverrideProvider from lms.djangoapps.ccx.models import CcxFieldOverride, CustomCourseForEdX @@ -67,7 +67,7 @@ def get_current_ccx(course_key): if not isinstance(course_key, CCXLocator): return None - ccx_cache = request_cache.get_cache('ccx') + ccx_cache = get_cache('ccx') if course_key not in ccx_cache: ccx_cache[course_key] = CustomCourseForEdX.objects.get(pk=course_key.ccx) @@ -120,7 +120,7 @@ def _get_overrides_for_ccx(ccx): Returns a dictionary mapping field name to overriden value for any overrides set on this block for this CCX. """ - overrides_cache = request_cache.get_cache('ccx-overrides') + overrides_cache = get_cache('ccx-overrides') if ccx not in overrides_cache: overrides = {} diff --git a/lms/djangoapps/ccx/tests/test_field_override_performance.py b/lms/djangoapps/ccx/tests/test_field_override_performance.py index 284f23b8c9..2db25120e4 100644 --- a/lms/djangoapps/ccx/tests/test_field_override_performance.py +++ b/lms/djangoapps/ccx/tests/test_field_override_performance.py @@ -22,7 +22,7 @@ from opaque_keys.edx.keys import CourseKey from openedx.core.djangoapps.content.block_structure.api import get_course_in_cache from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES from pytz import UTC -from request_cache.middleware import RequestCache +from openedx.core.djangoapps.request_cache.middleware import RequestCache from student.models import CourseEnrollment from student.tests.factories import UserFactory from xblock.core import XBlock diff --git a/lms/djangoapps/ccx/tests/test_overrides.py b/lms/djangoapps/ccx/tests/test_overrides.py index 51ede06489..f53680b9d3 100644 --- a/lms/djangoapps/ccx/tests/test_overrides.py +++ b/lms/djangoapps/ccx/tests/test_overrides.py @@ -17,7 +17,7 @@ from lms.djangoapps.ccx.models import CustomCourseForEdX from lms.djangoapps.ccx.overrides import override_field_for_ccx from lms.djangoapps.ccx.tests.utils import flatten, iter_blocks from lms.djangoapps.courseware.tests.test_field_overrides import inject_field_overrides -from request_cache.middleware import RequestCache +from openedx.core.djangoapps.request_cache.middleware import RequestCache from student.tests.factories import AdminFactory from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory diff --git a/lms/djangoapps/ccx/tests/test_views.py b/lms/djangoapps/ccx/tests/test_views.py index 21c00d1152..6d88d0d814 100644 --- a/lms/djangoapps/ccx/tests/test_views.py +++ b/lms/djangoapps/ccx/tests/test_views.py @@ -37,7 +37,7 @@ from lms.djangoapps.ccx.views import get_date from lms.djangoapps.grades.tasks import compute_all_grades_for_course from lms.djangoapps.instructor.access import allow_access, list_with_level from openedx.core.djangoapps.content.course_overviews.models import CourseOverview -from request_cache.middleware import RequestCache +from openedx.core.djangoapps.request_cache.middleware import RequestCache from student.models import CourseEnrollment, CourseEnrollmentAllowed from student.roles import CourseCcxCoachRole, CourseInstructorRole, CourseStaffRole from student.tests.factories import AdminFactory, CourseEnrollmentFactory, UserFactory diff --git a/lms/djangoapps/commerce/signals.py b/lms/djangoapps/commerce/signals.py index eb0846eadb..bf909b8409 100644 --- a/lms/djangoapps/commerce/signals.py +++ b/lms/djangoapps/commerce/signals.py @@ -9,7 +9,7 @@ from django.contrib.auth.models import AnonymousUser from django.dispatch import receiver from openedx.core.djangoapps.commerce.utils import is_commerce_service_configured -from request_cache.middleware import RequestCache +from openedx.core.djangoapps.request_cache.middleware import RequestCache from student.signals import REFUND_ORDER from .utils import refund_seat diff --git a/lms/djangoapps/courseware/context_processor.py b/lms/djangoapps/courseware/context_processor.py index ecc1efbd3a..143cbbeb34 100644 --- a/lms/djangoapps/courseware/context_processor.py +++ b/lms/djangoapps/courseware/context_processor.py @@ -5,7 +5,7 @@ This is meant to simplify the process of sending user preferences (espec. time_z to the templates without having to append every view file. """ -import request_cache +from openedx.core.djangoapps.request_cache import get_cache from openedx.core.djangoapps.user_api.errors import UserAPIInternalError, UserNotFound from openedx.core.djangoapps.user_api.preferences.api import get_user_preferences @@ -25,7 +25,7 @@ def user_timezone_locale_prefs(request): system/browser set time_zones and languages """ - cached_value = request_cache.get_cache(CACHE_NAME) + cached_value = get_cache(CACHE_NAME) if not cached_value: user_prefs = { 'user_timezone': None, diff --git a/lms/djangoapps/courseware/course_tools.py b/lms/djangoapps/courseware/course_tools.py index 0ca6708bf4..25747b374a 100644 --- a/lms/djangoapps/courseware/course_tools.py +++ b/lms/djangoapps/courseware/course_tools.py @@ -10,7 +10,7 @@ from course_modes.models import CourseMode from openedx.features.course_experience.course_tools import CourseTool from student.models import CourseEnrollment from courseware.date_summary import verified_upgrade_deadline_link -from request_cache import get_request +from openedx.core.djangoapps.request_cache import get_request class VerifiedUpgradeTool(CourseTool): diff --git a/lms/djangoapps/courseware/field_overrides.py b/lms/djangoapps/courseware/field_overrides.py index 5b580cd95a..dd57b5af6f 100644 --- a/lms/djangoapps/courseware/field_overrides.py +++ b/lms/djangoapps/courseware/field_overrides.py @@ -21,7 +21,7 @@ from contextlib import contextmanager from django.conf import settings from xblock.field_data import FieldData -from request_cache.middleware import RequestCache +from openedx.core.djangoapps.request_cache.middleware import RequestCache from xmodule.modulestore.inheritance import InheritanceMixin NOTSET = object() diff --git a/lms/djangoapps/django_comment_client/permissions.py b/lms/djangoapps/django_comment_client/permissions.py index 9731582cfb..e10fd1e531 100644 --- a/lms/djangoapps/django_comment_client/permissions.py +++ b/lms/djangoapps/django_comment_client/permissions.py @@ -11,7 +11,7 @@ from django_comment_common.models import CourseDiscussionSettings, all_permissio from django_comment_common.utils import get_course_discussion_settings from lms.djangoapps.teams.models import CourseTeam from lms.lib.comment_client import Thread -from request_cache.middleware import RequestCache, request_cached +from openedx.core.djangoapps.request_cache.middleware import RequestCache, request_cached def has_permission(user, permission, course_id=None): diff --git a/lms/djangoapps/django_comment_client/utils.py b/lms/djangoapps/django_comment_client/utils.py index 630bf1185f..cd197ac232 100644 --- a/lms/djangoapps/django_comment_client/utils.py +++ b/lms/djangoapps/django_comment_client/utils.py @@ -22,7 +22,7 @@ from django_comment_common.models import FORUM_ROLE_STUDENT, CourseDiscussionSet from django_comment_common.utils import get_course_discussion_settings from openedx.core.djangoapps.content.course_structures.models import CourseStructure from openedx.core.djangoapps.course_groups.cohorts import get_cohort_id, get_cohort_names, is_course_cohorted -from request_cache.middleware import request_cached +from openedx.core.djangoapps.request_cache.middleware import request_cached from student.models import get_user_by_username_or_email from student.roles import GlobalStaff from xmodule.modulestore.django import modulestore diff --git a/lms/djangoapps/gating/tests/test_integration.py b/lms/djangoapps/gating/tests/test_integration.py index 6616935239..6880957b5d 100644 --- a/lms/djangoapps/gating/tests/test_integration.py +++ b/lms/djangoapps/gating/tests/test_integration.py @@ -11,7 +11,7 @@ from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory from lms.djangoapps.grades.tests.utils import answer_problem from openedx.core.djangolib.testing.utils import get_mock_request from openedx.core.lib.gating import api as gating_api -from request_cache.middleware import RequestCache +from openedx.core.djangoapps.request_cache.middleware import RequestCache from student.tests.factories import UserFactory from xmodule.modulestore.django import modulestore from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase diff --git a/lms/djangoapps/grades/config/models.py b/lms/djangoapps/grades/config/models.py index 4bf868a6fd..778b4ee49f 100644 --- a/lms/djangoapps/grades/config/models.py +++ b/lms/djangoapps/grades/config/models.py @@ -8,7 +8,7 @@ from django.db.models import BooleanField, IntegerField, TextField from six import text_type from openedx.core.djangoapps.xmodule_django.models import CourseKeyField -from request_cache.middleware import request_cached +from openedx.core.djangoapps.request_cache.middleware import request_cached class PersistentGradesEnabledFlag(ConfigurationModel): diff --git a/lms/djangoapps/grades/config/tests/utils.py b/lms/djangoapps/grades/config/tests/utils.py index a948a8329e..89a910c31b 100644 --- a/lms/djangoapps/grades/config/tests/utils.py +++ b/lms/djangoapps/grades/config/tests/utils.py @@ -5,7 +5,7 @@ to configure flags related to persistent grading. from contextlib import contextmanager from lms.djangoapps.grades.config.models import CoursePersistentGradesFlag, PersistentGradesEnabledFlag -from request_cache.middleware import RequestCache +from openedx.core.djangoapps.request_cache.middleware import RequestCache @contextmanager diff --git a/lms/djangoapps/grades/models.py b/lms/djangoapps/grades/models.py index b57e33ed99..a72c77eaea 100644 --- a/lms/djangoapps/grades/models.py +++ b/lms/djangoapps/grades/models.py @@ -22,7 +22,7 @@ from opaque_keys.edx.keys import CourseKey, UsageKey from coursewarehistoryextended.fields import UnsignedBigIntAutoField, UnsignedBigIntOneToOneField from openedx.core.djangoapps.xmodule_django.models import CourseKeyField, UsageKeyField -from request_cache import get_cache +from openedx.core.djangoapps.request_cache import get_cache import events diff --git a/lms/djangoapps/instructor_task/tests/test_tasks_helper.py b/lms/djangoapps/instructor_task/tests/test_tasks_helper.py index 5111cdb38d..f3c44058be 100644 --- a/lms/djangoapps/instructor_task/tests/test_tasks_helper.py +++ b/lms/djangoapps/instructor_task/tests/test_tasks_helper.py @@ -66,7 +66,7 @@ from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory from openedx.core.djangoapps.credit.tests.factories import CreditCourseFactory from openedx.core.djangoapps.user_api.partition_schemes import RandomUserPartitionScheme from openedx.core.djangoapps.util.testing import ContentGroupTestCase, TestConditionalContent -from request_cache.middleware import RequestCache +from openedx.core.djangoapps.request_cache.middleware import RequestCache from shoppingcart.models import ( Coupon, CourseRegistrationCode, diff --git a/lms/djangoapps/lms_xblock/runtime.py b/lms/djangoapps/lms_xblock/runtime.py index f4be8eebf3..66f1f7d8b2 100644 --- a/lms/djangoapps/lms_xblock/runtime.py +++ b/lms/djangoapps/lms_xblock/runtime.py @@ -12,7 +12,7 @@ from lms.djangoapps.completion.services import CompletionService from openedx.core.djangoapps.user_api.course_tag import api as user_course_tag_api from openedx.core.lib.url_utils import quote_slashes from openedx.core.lib.xblock_utils import xblock_local_resource_url -from request_cache.middleware import RequestCache +from openedx.core.djangoapps.request_cache.middleware import RequestCache from xmodule.library_tools import LibraryToolsService from xmodule.modulestore.django import ModuleI18nService, modulestore from xmodule.partitions.partitions_service import PartitionService diff --git a/lms/djangoapps/mobile_api/middleware.py b/lms/djangoapps/mobile_api/middleware.py index 65c6a3fe59..79a91b7f3a 100644 --- a/lms/djangoapps/mobile_api/middleware.py +++ b/lms/djangoapps/mobile_api/middleware.py @@ -8,7 +8,7 @@ from django.core.cache import cache from django.http import HttpResponse from pytz import UTC -import request_cache +from openedx.core.djangoapps.request_cache import get_cache from mobile_api.mobile_platform import MobilePlatform from mobile_api.models import AppVersionConfig from mobile_api.utils import parsed_version @@ -52,7 +52,7 @@ class AppVersionUpgrade(object): 2. EDX-APP-VERSION-LAST-SUPPORTED-DATE; if user app version < min supported version and timestamp < expiry of that version """ - request_cache_dict = request_cache.get_cache(self.REQUEST_CACHE_NAME) + request_cache_dict = get_cache(self.REQUEST_CACHE_NAME) if request_cache_dict: last_supported_date = request_cache_dict[self.LAST_SUPPORTED_DATE_HEADER] if last_supported_date != self.NO_LAST_SUPPORTED_DATE: @@ -92,7 +92,7 @@ class AppVersionUpgrade(object): if user_agent: platform = self._get_platform(request, user_agent) if platform: - request_cache_dict = request_cache.get_cache(self.REQUEST_CACHE_NAME) + request_cache_dict = get_cache(self.REQUEST_CACHE_NAME) request_cache_dict[self.USER_APP_VERSION] = platform.version last_supported_date_cache_key = self._get_cache_key_name( self.LAST_SUPPORTED_DATE_HEADER, diff --git a/lms/djangoapps/teams/search_indexes.py b/lms/djangoapps/teams/search_indexes.py index 69ea9d1121..9f754751c0 100644 --- a/lms/djangoapps/teams/search_indexes.py +++ b/lms/djangoapps/teams/search_indexes.py @@ -11,7 +11,7 @@ from elasticsearch.exceptions import ConnectionError from search.search_engine_base import SearchEngine from lms.djangoapps.teams.models import CourseTeam -from request_cache import get_request_or_stub +from openedx.core.djangoapps.request_cache import get_request_or_stub from .errors import ElasticSearchConnectionError from .serializers import CourseTeamSerializer diff --git a/lms/envs/common.py b/lms/envs/common.py index ee2a0f8a2b..05c2bd52ba 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -1267,7 +1267,7 @@ else: MIDDLEWARE_CLASSES = [ 'crum.CurrentRequestUserMiddleware', - 'request_cache.middleware.RequestCache', + 'openedx.core.djangoapps.request_cache.middleware.RequestCache', 'openedx.core.djangoapps.monitoring_utils.middleware.MonitoringCustomMetrics', 'mobile_api.middleware.AppVersionUpgrade', @@ -3332,7 +3332,7 @@ AUDIT_CERT_CUTOFF_DATE = None CREDENTIALS_SERVICE_USERNAME = 'credentials_service_user' CREDENTIALS_GENERATION_ROUTING_KEY = HIGH_PRIORITY_QUEUE -WIKI_REQUEST_CACHE_MIDDLEWARE_CLASS = "request_cache.middleware.RequestCache" +WIKI_REQUEST_CACHE_MIDDLEWARE_CLASS = "openedx.core.djangoapps.request_cache.middleware.RequestCache" # Settings for Comprehensive Theming app diff --git a/openedx/core/djangoapps/bookmarks/services.py b/openedx/core/djangoapps/bookmarks/services.py index 92e22b3bd0..4560040a03 100644 --- a/openedx/core/djangoapps/bookmarks/services.py +++ b/openedx/core/djangoapps/bookmarks/services.py @@ -5,7 +5,7 @@ import logging from django.core.exceptions import ObjectDoesNotExist -from request_cache.middleware import RequestCache +from openedx.core.djangoapps.request_cache.middleware import RequestCache from xmodule.modulestore.django import modulestore from xmodule.modulestore.exceptions import ItemNotFoundError diff --git a/openedx/core/djangoapps/content/block_structure/config/__init__.py b/openedx/core/djangoapps/content/block_structure/config/__init__.py index fdcf284dcc..1d0d4a7016 100644 --- a/openedx/core/djangoapps/content/block_structure/config/__init__.py +++ b/openedx/core/djangoapps/content/block_structure/config/__init__.py @@ -3,7 +3,7 @@ This module contains various configuration settings via waffle switches for the Block Structure framework. """ from openedx.core.djangoapps.waffle_utils import WaffleSwitchNamespace -from request_cache.middleware import request_cached +from openedx.core.djangoapps.request_cache.middleware import request_cached from .models import BlockStructureConfiguration diff --git a/openedx/core/djangoapps/course_groups/cohorts.py b/openedx/core/djangoapps/course_groups/cohorts.py index 6a82f2eaab..f287d18458 100644 --- a/openedx/core/djangoapps/course_groups/cohorts.py +++ b/openedx/core/djangoapps/course_groups/cohorts.py @@ -6,7 +6,6 @@ forums, and to the cohort admin views. import logging import random -import request_cache from courseware import courses from django.contrib.auth.models import User from django.core.exceptions import ValidationError @@ -17,7 +16,8 @@ from django.dispatch import receiver from django.http import Http404 from django.utils.translation import ugettext as _ from eventtracking import tracker -from request_cache.middleware import request_cached +from openedx.core.djangoapps.request_cache import clear_cache, get_cache +from openedx.core.djangoapps.request_cache.middleware import request_cached from student.models import get_user_by_username_or_email from .models import ( @@ -175,8 +175,8 @@ def bulk_cache_cohorts(course_key, users): """ # before populating the cache with another bulk set of data, # remove previously cached entries to keep memory usage low. - request_cache.clear_cache(COHORT_CACHE_NAMESPACE) - cache = request_cache.get_cache(COHORT_CACHE_NAMESPACE) + clear_cache(COHORT_CACHE_NAMESPACE) + cache = get_cache(COHORT_CACHE_NAMESPACE) if is_course_cohorted(course_key): cohorts_by_user = { @@ -215,7 +215,7 @@ def get_cohort(user, course_key, assign=True, use_cached=False): Raises: ValueError if the CourseKey doesn't exist. """ - cache = request_cache.get_cache(COHORT_CACHE_NAMESPACE) + cache = get_cache(COHORT_CACHE_NAMESPACE) cache_key = _cohort_cache_key(user.id, course_key) if use_cached and cache_key in cache: @@ -514,7 +514,7 @@ def get_group_info_for_cohort(cohort, use_cached=False): use_cached=True to use the cached value instead of fetching from the database. """ - cache = request_cache.get_cache(u"cohorts.get_group_info_for_cohort") + cache = get_cache(u"cohorts.get_group_info_for_cohort") cache_key = unicode(cohort.id) if use_cached and cache_key in cache: diff --git a/openedx/core/djangoapps/coursegraph/tasks.py b/openedx/core/djangoapps/coursegraph/tasks.py index 29e510a323..249fe0928e 100644 --- a/openedx/core/djangoapps/coursegraph/tasks.py +++ b/openedx/core/djangoapps/coursegraph/tasks.py @@ -12,7 +12,7 @@ from django.utils import six, timezone from opaque_keys.edx.keys import CourseKey from py2neo import Graph, Node, Relationship, authenticate, NodeSelector from py2neo.compat import integer, string, unicode as neo4j_unicode -from request_cache.middleware import RequestCache +from openedx.core.djangoapps.request_cache.middleware import RequestCache log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/credit/models.py b/openedx/core/djangoapps/credit/models.py index dda04453f1..ab6a16c663 100644 --- a/openedx/core/djangoapps/credit/models.py +++ b/openedx/core/djangoapps/credit/models.py @@ -23,7 +23,7 @@ from jsonfield.fields import JSONField from model_utils.models import TimeStampedModel from openedx.core.djangoapps.xmodule_django.models import CourseKeyField -from request_cache.middleware import RequestCache, ns_request_cached +from openedx.core.djangoapps.request_cache.middleware import RequestCache, ns_request_cached CREDIT_PROVIDER_ID_REGEX = r"[a-z,A-Z,0-9,\-]+" log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/monitoring_utils/middleware.py b/openedx/core/djangoapps/monitoring_utils/middleware.py index f0f5145ca8..433f31be4c 100644 --- a/openedx/core/djangoapps/monitoring_utils/middleware.py +++ b/openedx/core/djangoapps/monitoring_utils/middleware.py @@ -14,7 +14,7 @@ from uuid import uuid4 import psutil -import request_cache +from openedx.core.djangoapps.request_cache import get_cache from openedx.core.djangoapps.waffle_utils import WaffleSwitchNamespace log = logging.getLogger(__name__) @@ -41,7 +41,7 @@ class MonitoringCustomMetrics(object): Get a reference to the part of the request cache wherein we store New Relic custom metrics related to the current request. """ - return request_cache.get_cache(name=REQUEST_CACHE_KEY) + return get_cache(name=REQUEST_CACHE_KEY) @classmethod def accumulate_metric(cls, name, value): @@ -108,7 +108,7 @@ class MonitoringMemoryMiddleware(object): """ Namespaced request cache for tracking memory usage. """ - return request_cache.get_cache(name='monitoring_memory') + return get_cache(name='monitoring_memory') def _log_prefix(self, prefix, request): """ diff --git a/common/djangoapps/request_cache/__init__.py b/openedx/core/djangoapps/request_cache/__init__.py similarity index 97% rename from common/djangoapps/request_cache/__init__.py rename to openedx/core/djangoapps/request_cache/__init__.py index 4e64747f9b..da444e521c 100644 --- a/common/djangoapps/request_cache/__init__.py +++ b/openedx/core/djangoapps/request_cache/__init__.py @@ -13,7 +13,7 @@ import crum from django.conf import settings from django.test.client import RequestFactory -from request_cache import middleware +from openedx.core.djangoapps.request_cache import middleware log = logging.getLogger(__name__) diff --git a/common/djangoapps/request_cache/middleware.py b/openedx/core/djangoapps/request_cache/middleware.py similarity index 100% rename from common/djangoapps/request_cache/middleware.py rename to openedx/core/djangoapps/request_cache/middleware.py diff --git a/common/djangoapps/request_cache/tests.py b/openedx/core/djangoapps/request_cache/tests.py similarity index 98% rename from common/djangoapps/request_cache/tests.py rename to openedx/core/djangoapps/request_cache/tests.py index 1f8d76db61..c0c6223b18 100644 --- a/common/djangoapps/request_cache/tests.py +++ b/openedx/core/djangoapps/request_cache/tests.py @@ -8,8 +8,8 @@ from django.test import TestCase from django.test.utils import override_settings from mock import Mock -from request_cache import get_request_or_stub -from request_cache.middleware import RequestCache, request_cached +from openedx.core.djangoapps.request_cache import get_request_or_stub +from openedx.core.djangoapps.request_cache.middleware import RequestCache, request_cached from xmodule.modulestore.django import modulestore diff --git a/openedx/core/djangoapps/schedules/content_highlights.py b/openedx/core/djangoapps/schedules/content_highlights.py index 53b2ba91c1..777c5a581a 100644 --- a/openedx/core/djangoapps/schedules/content_highlights.py +++ b/openedx/core/djangoapps/schedules/content_highlights.py @@ -8,7 +8,7 @@ from courseware.module_render import get_module_for_descriptor from courseware.model_data import FieldDataCache from openedx.core.djangoapps.schedules.config import COURSE_UPDATE_WAFFLE_FLAG from openedx.core.djangoapps.schedules.exceptions import CourseUpdateDoesNotExist -from request_cache import get_request_or_stub +from openedx.core.djangoapps.request_cache import get_request_or_stub from xmodule.modulestore.django import modulestore diff --git a/openedx/core/djangoapps/theming/helpers.py b/openedx/core/djangoapps/theming/helpers.py index 41152ee747..914c31aaec 100644 --- a/openedx/core/djangoapps/theming/helpers.py +++ b/openedx/core/djangoapps/theming/helpers.py @@ -19,7 +19,7 @@ from openedx.core.djangoapps.theming.helpers_dirs import ( get_theme_dirs, get_themes_unchecked ) -from request_cache.middleware import RequestCache, request_cached +from openedx.core.djangoapps.request_cache.middleware import RequestCache, request_cached logger = getLogger(__name__) # pylint: disable=invalid-name diff --git a/openedx/core/djangoapps/theming/tests/test_helpers.py b/openedx/core/djangoapps/theming/tests/test_helpers.py index fb87596f0f..570cfb670a 100644 --- a/openedx/core/djangoapps/theming/tests/test_helpers.py +++ b/openedx/core/djangoapps/theming/tests/test_helpers.py @@ -12,7 +12,7 @@ from openedx.core.djangoapps.theming import helpers as theming_helpers from openedx.core.djangoapps.theming.helpers import get_template_path_with_theme, strip_site_theme_templates_path, \ get_themes, Theme, get_theme_base_dir from openedx.core.djangolib.testing.utils import skip_unless_cms, skip_unless_lms -from request_cache.middleware import RequestCache +from openedx.core.djangoapps.request_cache.middleware import RequestCache class TestHelpers(TestCase): diff --git a/openedx/core/djangoapps/user_api/course_tag/api.py b/openedx/core/djangoapps/user_api/course_tag/api.py index c2722d736f..cb8f2a997c 100644 --- a/openedx/core/djangoapps/user_api/course_tag/api.py +++ b/openedx/core/djangoapps/user_api/course_tag/api.py @@ -8,7 +8,7 @@ UserCourseTag model. """ from collections import defaultdict -from request_cache import get_cache +from openedx.core.djangoapps.request_cache import get_cache from ..models import UserCourseTag # Scopes diff --git a/openedx/core/djangoapps/verified_track_content/models.py b/openedx/core/djangoapps/verified_track_content/models.py index dcbead20e0..9359b97572 100644 --- a/openedx/core/djangoapps/verified_track_content/models.py +++ b/openedx/core/djangoapps/verified_track_content/models.py @@ -18,7 +18,7 @@ from openedx.core.djangoapps.course_groups.cohorts import ( ) from openedx.core.djangoapps.verified_track_content.tasks import sync_cohort_with_mode from openedx.core.djangoapps.xmodule_django.models import CourseKeyField -from request_cache.middleware import RequestCache, ns_request_cached +from openedx.core.djangoapps.request_cache.middleware import RequestCache, ns_request_cached from student.models import CourseEnrollment log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/waffle_utils/__init__.py b/openedx/core/djangoapps/waffle_utils/__init__.py index 3439f845bb..e317436104 100644 --- a/openedx/core/djangoapps/waffle_utils/__init__.py +++ b/openedx/core/djangoapps/waffle_utils/__init__.py @@ -54,7 +54,7 @@ import six from opaque_keys.edx.keys import CourseKey from waffle import flag_is_active, switch_is_active -from request_cache import get_cache as get_request_cache +from openedx.core.djangoapps.request_cache import get_cache as get_request_cache log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/waffle_utils/models.py b/openedx/core/djangoapps/waffle_utils/models.py index 779d8f6765..eeaf474a00 100644 --- a/openedx/core/djangoapps/waffle_utils/models.py +++ b/openedx/core/djangoapps/waffle_utils/models.py @@ -8,7 +8,7 @@ from six import text_type from config_models.models import ConfigurationModel from openedx.core.djangoapps.xmodule_django.models import CourseKeyField -from request_cache.middleware import request_cached +from openedx.core.djangoapps.request_cache.middleware import request_cached class WaffleFlagCourseOverrideModel(ConfigurationModel): diff --git a/openedx/core/djangoapps/waffle_utils/tests/test_init.py b/openedx/core/djangoapps/waffle_utils/tests/test_init.py index 7336b3938f..5568ce8afc 100644 --- a/openedx/core/djangoapps/waffle_utils/tests/test_init.py +++ b/openedx/core/djangoapps/waffle_utils/tests/test_init.py @@ -7,7 +7,7 @@ from django.test import TestCase from django.test.client import RequestFactory from mock import patch from opaque_keys.edx.keys import CourseKey -from request_cache.middleware import RequestCache +from openedx.core.djangoapps.request_cache.middleware import RequestCache from waffle.testutils import override_flag from .. import CourseWaffleFlag, WaffleFlagNamespace diff --git a/openedx/core/djangoapps/waffle_utils/tests/test_models.py b/openedx/core/djangoapps/waffle_utils/tests/test_models.py index 980a4dc082..5dbfbe0859 100644 --- a/openedx/core/djangoapps/waffle_utils/tests/test_models.py +++ b/openedx/core/djangoapps/waffle_utils/tests/test_models.py @@ -5,7 +5,7 @@ from ddt import data, ddt, unpack from django.test import TestCase from opaque_keys.edx.keys import CourseKey -from request_cache.middleware import RequestCache +from openedx.core.djangoapps.request_cache.middleware import RequestCache from ..models import WaffleFlagCourseOverrideModel diff --git a/openedx/core/djangoapps/waffle_utils/tests/test_testutils.py b/openedx/core/djangoapps/waffle_utils/tests/test_testutils.py index fa1ce59c4a..a10768f540 100644 --- a/openedx/core/djangoapps/waffle_utils/tests/test_testutils.py +++ b/openedx/core/djangoapps/waffle_utils/tests/test_testutils.py @@ -7,7 +7,7 @@ from django.test import TestCase from django.test.client import RequestFactory from opaque_keys.edx.keys import CourseKey -from request_cache.middleware import RequestCache +from openedx.core.djangoapps.request_cache.middleware import RequestCache from .. import CourseWaffleFlag, WaffleFlagNamespace from ..testutils import override_waffle_flag diff --git a/openedx/core/djangolib/testing/utils.py b/openedx/core/djangolib/testing/utils.py index c030275e6b..769fdb238c 100644 --- a/openedx/core/djangolib/testing/utils.py +++ b/openedx/core/djangolib/testing/utils.py @@ -19,7 +19,7 @@ from django.core.cache import caches from django.db import DEFAULT_DB_ALIAS, connections from django.test import RequestFactory, TestCase, override_settings from django.test.utils import CaptureQueriesContext -from request_cache.middleware import RequestCache +from openedx.core.djangoapps.request_cache.middleware import RequestCache class CacheIsolationMixin(object): diff --git a/openedx/core/lib/celery/task_utils.py b/openedx/core/lib/celery/task_utils.py index 1d8eb19a61..3c281aaa0e 100644 --- a/openedx/core/lib/celery/task_utils.py +++ b/openedx/core/lib/celery/task_utils.py @@ -3,7 +3,7 @@ from contextlib import contextmanager from crum import CurrentRequestUserMiddleware from openedx.core.djangoapps.theming.middleware import CurrentSiteThemeMiddleware from django.http import HttpResponse -from request_cache import get_request_or_stub +from openedx.core.djangoapps.request_cache import get_request_or_stub @contextmanager diff --git a/openedx/features/course_experience/utils.py b/openedx/features/course_experience/utils.py index f8c237b505..639bb7972b 100644 --- a/openedx/features/course_experience/utils.py +++ b/openedx/features/course_experience/utils.py @@ -5,7 +5,7 @@ from opaque_keys.edx.keys import CourseKey from lms.djangoapps.course_api.blocks.api import get_blocks from lms.djangoapps.course_blocks.utils import get_student_module_as_dict -from request_cache.middleware import request_cached +from openedx.core.djangoapps.request_cache.middleware import request_cached from xmodule.modulestore.django import modulestore