Commit d92311f7 authored by Ivan Tyagov's avatar Ivan Tyagov Committed by Julien Muchembled

Add set and get API testing and a short algorithm optimization comment.

parent eaf81382
......@@ -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
......
......@@ -484,7 +484,8 @@ return 'a' * 1024 * 1024 * 25
print "\n\tCalculation 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
"""
......
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