Commit 88cb9548 by Christopher Lee

Do not track Add/Remove Product when calculating basket

LEARNER-4968
parent b140c429
...@@ -6,14 +6,73 @@ is installed in order to clear the cache after each request. ...@@ -6,14 +6,73 @@ is installed in order to clear the cache after each request.
""" """
import logging import logging
from urlparse import urlparse
from django.core.cache import caches from django.core.cache import caches
from django.core.cache.backends.base import BaseCache from django.core.cache.backends.base import BaseCache
from django.conf import settings
from django.test.client import RequestFactory
from ecommerce.request_cache import middleware
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
def get_cache(name):
"""
Return the request cache named ``name``.
Arguments:
name (str): The name of the request cache to load
Returns: dict
"""
return middleware.RequestCache.get_request_cache(name)
def get_request():
"""
Return the current request.
"""
return middleware.RequestCache.get_current_request()
def get_request_or_stub():
"""
Return the current request or a stub request.
If called outside the context of a request, construct a fake
request that can be used to build an absolute URI.
This is useful in cases where we need to pass in a request object
but don't have an active request (for example, in test cases).
"""
request = get_request()
if request is None:
log.warning(
"Could not retrieve the current request. "
"A stub request will be created instead using settings.SITE_NAME. "
"This should be used *only* in test cases, never in production!"
)
# The settings SITE_NAME may contain a port number, so we need to
# parse the full URL.
full_url = "http://{site_name}".format(site_name=settings.SITE_NAME)
parsed_url = urlparse(full_url)
# Construct the fake request. This can be used to construct absolute
# URIs to other paths.
return RequestFactory(
SERVER_NAME=parsed_url.hostname,
SERVER_PORT=parsed_url.port or 80,
).get("/")
else:
return request
class RequestPlusRemoteCache(BaseCache): class RequestPlusRemoteCache(BaseCache):
""" """
This Django cache backend implements two layers of caching. This Django cache backend implements two layers of caching.
......
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