Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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
edx-platform
Commits
dced13a8
Commit
dced13a8
authored
May 10, 2016
by
Nimisha Asthagiri
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12397 from edx/tnl/block-transformer-memcache
Set infinite timeout for Block Structure cache entries
parents
e8d2a626
68173b6d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
12 deletions
+25
-12
openedx/core/lib/block_structure/cache.py
+8
-2
openedx/core/lib/block_structure/tests/helpers.py
+3
-1
openedx/core/lib/block_structure/tests/test_cache.py
+14
-9
No files found.
openedx/core/lib/block_structure/cache.py
View file @
dced13a8
...
...
@@ -41,13 +41,19 @@ class BlockStructureCache(object):
data_to_cache
=
(
block_structure
.
_block_relations
,
block_structure
.
_transformer_data
,
block_structure
.
_block_data_map
block_structure
.
_block_data_map
,
)
zp_data_to_cache
=
zpickle
(
data_to_cache
)
# Set the timeout value for the cache to None. This caches the
# value forever. The expectation is that the caller will delete
# the cached value once it is outdated.
self
.
_cache
.
set
(
self
.
_encode_root_cache_key
(
block_structure
.
root_block_usage_key
),
zp_data_to_cache
zp_data_to_cache
,
timeout
=
None
,
)
logger
.
info
(
"Wrote BlockStructure
%
s to cache, size:
%
s"
,
block_structure
.
root_block_usage_key
,
...
...
openedx/core/lib/block_structure/tests/helpers.py
View file @
dced13a8
...
...
@@ -78,13 +78,15 @@ class MockCache(object):
# An in-memory map of cache keys to cache values.
self
.
map
=
{}
self
.
set_call_count
=
0
self
.
timeout_from_last_call
=
0
def
set
(
self
,
key
,
val
):
def
set
(
self
,
key
,
val
,
timeout
):
"""
Associates the given key with the given value in the cache.
"""
self
.
set_call_count
+=
1
self
.
map
[
key
]
=
val
self
.
timeout_from_last_call
=
timeout
def
get
(
self
,
key
,
default
=
None
):
"""
...
...
openedx/core/lib/block_structure/tests/test_cache.py
View file @
dced13a8
...
...
@@ -11,13 +11,14 @@ from .helpers import ChildrenMapTestMixin, MockCache, MockTransformer
@attr
(
'shard_2'
)
class
TestBlockStructureCache
(
ChildrenMapTestMixin
,
TestCase
):
"""
Tests for BlockStructure
Factory
Tests for BlockStructure
Cache
"""
def
setUp
(
self
):
super
(
TestBlockStructureCache
,
self
)
.
setUp
()
self
.
children_map
=
self
.
SIMPLE_CHILDREN_MAP
self
.
block_structure
=
self
.
create_block_structure
(
self
.
children_map
)
self
.
cache
=
BlockStructureCache
(
MockCache
())
self
.
mock_cache
=
MockCache
()
self
.
block_structure_cache
=
BlockStructureCache
(
self
.
mock_cache
)
def
add_transformers
(
self
):
"""
...
...
@@ -30,22 +31,26 @@ class TestBlockStructureCache(ChildrenMapTestMixin, TestCase):
usage_key
=
0
,
transformer
=
transformer
,
key
=
'test'
,
value
=
'{} val'
.
format
(
transformer
.
name
())
)
def
test_add
(
self
):
def
test_add_and_get
(
self
):
self
.
assertEquals
(
self
.
mock_cache
.
timeout_from_last_call
,
0
)
self
.
add_transformers
()
self
.
cache
.
add
(
self
.
block_structure
)
cached_value
=
self
.
cache
.
get
(
self
.
block_structure
.
root_block_usage_key
)
self
.
block_structure_cache
.
add
(
self
.
block_structure
)
self
.
assertEquals
(
self
.
mock_cache
.
timeout_from_last_call
,
None
)
cached_value
=
self
.
block_structure_cache
.
get
(
self
.
block_structure
.
root_block_usage_key
)
self
.
assertIsNotNone
(
cached_value
)
self
.
assert_block_structure
(
cached_value
,
self
.
children_map
)
def
test_get_none
(
self
):
self
.
assertIsNone
(
self
.
cache
.
get
(
self
.
block_structure
.
root_block_usage_key
)
self
.
block_structure_
cache
.
get
(
self
.
block_structure
.
root_block_usage_key
)
)
def
test_delete
(
self
):
self
.
add_transformers
()
self
.
cache
.
add
(
self
.
block_structure
)
self
.
cache
.
delete
(
self
.
block_structure
.
root_block_usage_key
)
self
.
block_structure_
cache
.
add
(
self
.
block_structure
)
self
.
block_structure_
cache
.
delete
(
self
.
block_structure
.
root_block_usage_key
)
self
.
assertIsNone
(
self
.
cache
.
get
(
self
.
block_structure
.
root_block_usage_key
)
self
.
block_structure_
cache
.
get
(
self
.
block_structure
.
root_block_usage_key
)
)
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