Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
ecommerce
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
ecommerce
Commits
88cb9548
Commit
88cb9548
authored
Apr 19, 2018
by
Christopher Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not track Add/Remove Product when calculating basket
LEARNER-4968
parent
b140c429
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
0 deletions
+59
-0
ecommerce/request_cache/__init__.py
+59
-0
No files found.
ecommerce/request_cache/__init__.py
View file @
88cb9548
...
@@ -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.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment