Adding cache implementation for the programs api.
ECOM-2832
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""
|
||||
Helper methods for Programs.
|
||||
"""
|
||||
from django.core.cache import cache
|
||||
from edx_rest_api_client.client import EdxRestApiClient
|
||||
from openedx.core.djangoapps.programs.models import ProgramsApiConfig
|
||||
|
||||
@@ -20,3 +21,29 @@ def programs_api_client(api_url, jwt_access_token):
|
||||
api_url,
|
||||
jwt=jwt_access_token
|
||||
)
|
||||
|
||||
|
||||
def is_cache_enabled_for_programs(): # pylint: disable=invalid-name
|
||||
"""Returns a Boolean indicating whether responses from the Programs API
|
||||
will be cached.
|
||||
"""
|
||||
return ProgramsApiConfig.current().is_cache_enabled
|
||||
|
||||
|
||||
def set_cached_programs_response(programs_data):
|
||||
""" Set cache value for the programs data with specific ttl.
|
||||
|
||||
Arguments:
|
||||
programs_data (dict): Programs data in dictionary format
|
||||
"""
|
||||
cache.set(
|
||||
ProgramsApiConfig.PROGRAMS_API_CACHE_KEY,
|
||||
programs_data,
|
||||
ProgramsApiConfig.current().cache_ttl
|
||||
)
|
||||
|
||||
|
||||
def get_cached_programs_response():
|
||||
""" Get programs data from cache against cache key."""
|
||||
cache_key = ProgramsApiConfig.PROGRAMS_API_CACHE_KEY
|
||||
return cache.get(cache_key)
|
||||
|
||||
Reference in New Issue
Block a user