Skip to content

Commit

Permalink
Change the cache from memcache to redis in the task as well as it is …
Browse files Browse the repository at this point in the history
…in the util function itself (#2263)
  • Loading branch information
JenniWhitman authored Jun 20, 2024
1 parent 75b6250 commit 00b42b2
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions cms/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from urllib.parse import urljoin, urlparse

import requests
from django.core.cache import cache
from django.core.cache import caches
from mitol.common.decorators import single_task

from cms.api import create_featured_items
Expand Down Expand Up @@ -105,13 +105,14 @@ def queue_fastly_full_purge():
@single_task(10)
def refresh_featured_homepage_items():
"""
Refresh the featured homepage items in the memcached cache.
Refresh the featured homepage items in the redis cache.
"""
logger = logging.getLogger("refresh_featured_homepage_items__task")
logger.info("Refreshing featured homepage items...")
# if the key is not found, the ttl will be 0 per their docs
# https://github.com/jazzband/django-redis?tab=readme-ov-file#get-ttl-time-to-live-from-key
if cache.ttl("CMS_homepage_featured_courses") > (10 * ONE_MINUTE):
redis_cache = caches["redis"]
if redis_cache.ttl("CMS_homepage_featured_courses") > (10 * ONE_MINUTE):
logger.info("Featured courses found in cache, moving on")
return
logger.info("No featured courses found in cache, refreshing")
Expand Down

0 comments on commit 00b42b2

Please sign in to comment.