remove expired cache with config.cfgimpl_reset_cache(True)
This commit is contained in:
@ -181,7 +181,7 @@ class Setting(object):
|
||||
if propname not in props:
|
||||
props.append(propname)
|
||||
self.set_properties(props)
|
||||
self.context.cfgimpl_clean_cache()
|
||||
self.context.cfgimpl_reset_cache()
|
||||
|
||||
def disable_property(self, propname):
|
||||
"deletes property propname in the Config's properties attribute"
|
||||
@ -189,7 +189,7 @@ class Setting(object):
|
||||
if propname in props:
|
||||
props.remove(propname)
|
||||
self.set_properties(props)
|
||||
self.context.cfgimpl_clean_cache()
|
||||
self.context.cfgimpl_reset_cache()
|
||||
|
||||
def set_properties(self, properties, opt=None):
|
||||
"""save properties for specified opt
|
||||
@ -209,14 +209,14 @@ class Setting(object):
|
||||
if not propname in properties:
|
||||
properties.append(propname)
|
||||
self.set_properties(properties, opt)
|
||||
self.context.cfgimpl_clean_cache()
|
||||
self.context.cfgimpl_reset_cache()
|
||||
|
||||
def del_property(self, propname, opt, is_apply_req=True):
|
||||
properties = self.get_properties(opt, is_apply_req)
|
||||
if propname in properties:
|
||||
properties.remove(propname)
|
||||
self.set_properties(properties, opt)
|
||||
self.context.cfgimpl_clean_cache()
|
||||
self.context.cfgimpl_reset_cache()
|
||||
|
||||
def _validate_mandatory(self, opt, value, force_properties=None):
|
||||
set_mandatory = self.has_property('mandatory')
|
||||
@ -248,9 +248,9 @@ class Setting(object):
|
||||
force_properties=None):
|
||||
is_cached = False
|
||||
if opt_or_descr in self._cache:
|
||||
t = time()
|
||||
exp = time()
|
||||
props, raise_text, created = self._cache[opt_or_descr]
|
||||
if t < created:
|
||||
if exp < created:
|
||||
properties = props
|
||||
is_cached = True
|
||||
if not is_cached:
|
||||
@ -320,8 +320,16 @@ class Setting(object):
|
||||
if self.has_property('expire'):
|
||||
self._cache[opt] = (props, raise_text, time() + expires_time)
|
||||
|
||||
def reset_cache(self):
|
||||
self._cache = {}
|
||||
def reset_cache(self, only_expired):
|
||||
if only_expired:
|
||||
exp = time()
|
||||
keys = self._cache.keys()
|
||||
for key in keys:
|
||||
props, raise_text, created = self._cache[key]
|
||||
if exp > created:
|
||||
del(self._cache[key])
|
||||
else:
|
||||
self._cache.clear()
|
||||
|
||||
|
||||
def apply_requires(opt, config):
|
||||
|
Reference in New Issue
Block a user