Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tatuya Kamada
erp5
Commits
d92311f7
Commit
d92311f7
authored
Oct 30, 2012
by
Ivan Tyagov
Committed by
Julien Muchembled
Nov 05, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add set and get API testing and a short algorithm optimization comment.
parent
eaf81382
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
1 deletion
+47
-1
product/ERP5Type/Core/CacheBag.py
product/ERP5Type/Core/CacheBag.py
+5
-0
product/ERP5Type/tests/testCacheTool.py
product/ERP5Type/tests/testCacheTool.py
+42
-1
No files found.
product/ERP5Type/Core/CacheBag.py
View file @
d92311f7
...
...
@@ -61,6 +61,11 @@ class CacheBag(CacheFactory):
value
=
data_dict
.
getValue
()
if
ram_cache_factory_plugin_list
.
index
(
cache_plugin
)
>
0
:
# update first plugin as it's the one to be used
# XXX: JPS we can have different update policy here based on a project requirements.
# c0 c1 c2....cN where c0 is filled from cN
# c1.... cN-1 untouched then rotate i -> i+1
# this way you can create "groups of caches" per date and trash old stuff
# instead of using 2x more disk space, you can use 1/N more disk space
cache_duration
=
self
.
getRamCacheFactory
().
cache_duration
ram_cache_factory_plugin_list
[
0
].
set
(
cache_id
,
DEFAULT_CACHE_SCOPE
,
value
,
cache_duration
)
return
value
...
...
product/ERP5Type/tests/testCacheTool.py
View file @
d92311f7
...
...
@@ -484,7 +484,8 @@ return 'a' * 1024 * 1024 * 25
print
"
\
n
\
t
Calculation time (3rd call)"
,
calculation_time
def
test_06_CheckCacheBag
(
self
):
"""Check Cache Bag
"""
Check Cache Bag
"""
portal_caches
=
self
.
portal
.
portal_caches
...
...
@@ -516,6 +517,46 @@ return 'a' * 1024 * 1024 * 25
self
.
assertEqual
(
'value_for_y'
,
cache_bag
.
get
(
'y'
))
self
.
assertEqual
(
'value_for_y'
,
ram_cache_factory_plugin_list
[
0
].
get
(
'y'
,
DEFAULT_CACHE_SCOPE
).
getValue
())
def
test_07_CheckCacheFactory
(
self
):
"""
Check Cache Factory set and get API.
"""
portal_caches
=
self
.
portal
.
portal_caches
cache_factory
=
portal_caches
.
newContent
(
portal_type
=
"Cache Factory"
,
cache_duration
=
3600
)
cache_plugin1
=
cache_factory
.
newContent
(
portal_type
=
"Ram Cache"
)
cache_plugin1
.
setIntIndex
(
0
)
cache_bag1
=
cache_factory
.
newContent
(
portal_type
=
"Cache Bag"
,
cache_duration
=
3600
)
cache_bag1
.
setIntIndex
(
1
)
ram_cache1
=
cache_bag1
.
newContent
(
portal_type
=
"Ram Cache"
)
ram_cache2
=
cache_bag1
.
newContent
(
portal_type
=
"Ram Cache"
)
self
.
tic
()
# test get / set API
cache_factory
.
set
(
'x'
,
'value_for_x'
)
self
.
assertEqual
(
'value_for_x'
,
cache_factory
.
get
(
'x'
))
# test that all cache plugin have this set
self
.
assertEqual
(
'value_for_x'
,
cache_plugin1
.
get
(
'x'
))
self
.
assertEqual
(
'value_for_x'
,
cache_bag1
.
get
(
'x'
))
# test set on individual cache plugin as this cache plugin has highest priority
# it will affect what root Cache Factory returns
cache_plugin1
.
set
(
'x'
,
'new_value_for_x'
)
self
.
assertEqual
(
'new_value_for_x'
,
cache_plugin1
.
get
(
'x'
))
self
.
assertEqual
(
'new_value_for_x'
,
cache_factory
.
get
(
'x'
))
# others cache plugins will remain with old value until ...
self
.
assertEqual
(
'value_for_x'
,
cache_bag1
.
get
(
'x'
))
# .. root Cache Factory set will update all
cache_factory
.
set
(
'x'
,
'new_value_for_x'
)
self
.
assertEqual
(
cache_factory
.
get
(
'x'
),
cache_plugin1
.
get
(
'x'
))
self
.
assertEqual
(
cache_plugin1
.
get
(
'x'
),
cache_bag1
.
get
(
'x'
))
self
.
assertEqual
(
'new_value_for_x'
,
cache_factory
.
get
(
'x'
))
def
test_99_CachePluginInterface
(
self
):
"""Test Class against Interface
"""
...
...
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