better setcache implementation

This commit is contained in:
Emmanuel Garette 2018-08-18 08:35:30 +02:00
parent 89ccfa8aa1
commit 26095734bf
3 changed files with 12 additions and 15 deletions

View File

@ -349,7 +349,7 @@ class Settings(object):
None, None,
None, None,
{}, {},
None, {},
'context_props') 'context_props')
if not is_cached: if not is_cached:
meta = self._getcontext().cfgimpl_get_meta() meta = self._getcontext().cfgimpl_get_meta()
@ -361,8 +361,8 @@ class Settings(object):
self._p_.setcache(None, self._p_.setcache(None,
None, None,
props, props,
props, {},
None) props)
return props return props
def getproperties(self, def getproperties(self,
@ -384,7 +384,7 @@ class Settings(object):
expires_time, expires_time,
index, index,
props, props,
None, {},
'self_props') 'self_props')
else: else:
is_cached = False is_cached = False
@ -405,8 +405,7 @@ class Settings(object):
self._p_.setcache(path, self._p_.setcache(path,
index, index,
props, props,
config_bag.properties, props,
#FIXME
config_bag.properties) config_bag.properties)
return props return props

View File

@ -33,13 +33,11 @@ class Cache(DictCache):
self._storage = storage self._storage = storage
super().__init__() super().__init__()
def setcache(self, path, index, val, props, self_props): def setcache(self, path, index, val, self_props, props):
"""add val in cache for a specified path """add val in cache for a specified path
if slave, add index if slave, add index
""" """
#FIXME self_props n'est pas None ! if 'cache' in props or 'cache' in self_props:
if 'cache' in props or \
(self_props is not None and 'cache' in self_props):
if DEBUG: if DEBUG:
print('setcache {} with index {} and value {} in {} ({})'.format(path, index, val, print('setcache {} with index {} and value {} in {} ({})'.format(path, index, val,
_display_classname(self), _display_classname(self),
@ -75,10 +73,10 @@ class Cache(DictCache):
# so value is self_props # so value is self_props
self_props = value self_props = value
# recheck "cache" value # recheck "cache" value
if 'cache' in props or (self_props is not None and 'cache' in props): if 'cache' in props or 'cache' in props:
if expires_time and timestamp and \ if expires_time and timestamp and \
(props is not None and 'expire' in props or \ ('expire' in props or \
self_props is not None and 'expire' in self_props): 'expire' in self_props):
ntime = int(time()) ntime = int(time())
if timestamp + expires_time >= ntime: if timestamp + expires_time >= ntime:
if DEBUG: if DEBUG:

View File

@ -98,8 +98,8 @@ class Values(object):
self._p_.setcache(option_bag.path, self._p_.setcache(option_bag.path,
option_bag.index, option_bag.index,
value, value,
setting_properties, option_bag.properties,
option_bag.properties) setting_properties)
if isinstance(value, list): if isinstance(value, list):
# return a copy, so value cannot be modified # return a copy, so value cannot be modified
return value.copy() return value.copy()