can change expiration_time in api
This commit is contained in:
@ -22,7 +22,7 @@ from typing import List, Set, Any, Optional, Callable, Union, Dict
|
||||
from .error import APIError, ConfigError, LeadershipError, PropertiesOptionError
|
||||
from .i18n import _
|
||||
from .setting import ConfigBag, OptionBag, owners, groups, Undefined, undefined, \
|
||||
FORBIDDEN_SET_PROPERTIES, SPECIAL_PROPERTIES
|
||||
FORBIDDEN_SET_PROPERTIES, SPECIAL_PROPERTIES, EXPIRATION_TIME
|
||||
from .config import KernelConfig, SubConfig, KernelGroupConfig, KernelMetaConfig, KernelMixConfig
|
||||
from .option import ChoiceOption, OptionDescription
|
||||
|
||||
@ -1301,6 +1301,10 @@ class TiramisuContextCache(TiramisuContext):
|
||||
def reset(self):
|
||||
self._config_bag.context.cfgimpl_reset_cache(None, None)
|
||||
|
||||
def expiration_time(self,
|
||||
time: int):
|
||||
self._config_bag.expiration_time = time
|
||||
|
||||
|
||||
class TiramisuDispatcher:
|
||||
pass
|
||||
|
@ -23,14 +23,11 @@ from .error import (RequirementError, PropertiesOptionError,
|
||||
from .i18n import _
|
||||
|
||||
|
||||
"Default encoding for display a Config if raise UnicodeEncodeError"
|
||||
default_encoding = 'utf-8'
|
||||
|
||||
"""If cache and expire is enable, time before cache is expired.
|
||||
This delay start first time value/setting is set in cache, even if
|
||||
user access several time to value/setting
|
||||
"""
|
||||
expires_time = 5
|
||||
EXPIRATION_TIME = 5
|
||||
"""List of default properties (you can add new one if needed).
|
||||
|
||||
For common properties and personalise properties, if a propery is set for
|
||||
@ -68,7 +65,7 @@ cache
|
||||
if set, enable cache settings and values
|
||||
|
||||
expire
|
||||
if set, settings and values in cache expire after ``expires_time``
|
||||
if set, settings and values in cache expire after ``expiration_time``
|
||||
|
||||
everything_frozen
|
||||
whole option in config are frozen (even if option have not frozen
|
||||
@ -186,7 +183,9 @@ class ConfigBag:
|
||||
'properties', # properties for current context
|
||||
'true_properties', # properties for current context
|
||||
'permissives', # permissives for current context
|
||||
'expiration_time' # EXPIRATION_TIME
|
||||
)
|
||||
|
||||
def __init__(self, context, **kwargs):
|
||||
self.context = context
|
||||
for key, value in kwargs.items():
|
||||
@ -194,13 +193,18 @@ class ConfigBag:
|
||||
|
||||
def __getattr__(self, key):
|
||||
if key == 'properties':
|
||||
self.properties = self.context.cfgimpl_get_settings().get_context_properties()
|
||||
settings = self.context.cfgimpl_get_settings()
|
||||
self.properties = settings.get_context_properties()
|
||||
return self.properties
|
||||
if key == 'permissives':
|
||||
self.permissives = self.context.cfgimpl_get_settings().get_context_permissives()
|
||||
settings = self.context.cfgimpl_get_settings()
|
||||
self.permissives = settings.get_context_permissives()
|
||||
return self.permissives
|
||||
if key == 'true_properties':
|
||||
return self.properties
|
||||
if key == 'expiration_time':
|
||||
self.expiration_time = EXPIRATION_TIME
|
||||
return self.expiration_time
|
||||
raise KeyError('unknown key {} for ConfigBag'.format(key)) # pragma: no cover
|
||||
|
||||
def remove_warnings(self):
|
||||
@ -414,7 +418,7 @@ class Settings(object):
|
||||
if apply_requires:
|
||||
props = config_bag.properties
|
||||
is_cached, props = self._p_.getcache(path,
|
||||
expires_time,
|
||||
config_bag.expiration_time,
|
||||
index,
|
||||
props,
|
||||
{},
|
||||
|
@ -55,7 +55,7 @@ class Cache(DictCache):
|
||||
|
||||
def getcache(self,
|
||||
path,
|
||||
expires_time,
|
||||
expiration_time,
|
||||
index,
|
||||
props,
|
||||
self_props,
|
||||
@ -75,11 +75,11 @@ class Cache(DictCache):
|
||||
self_props = value
|
||||
# recheck "cache" value
|
||||
if 'cache' in props or 'cache' in props:
|
||||
if expires_time and timestamp and \
|
||||
if expiration_time and timestamp and \
|
||||
('expire' in props or \
|
||||
'expire' in self_props):
|
||||
ntime = int(time())
|
||||
if timestamp + expires_time >= ntime:
|
||||
if timestamp + expiration_time >= ntime:
|
||||
if DEBUG: # pragma: no cover
|
||||
print('getcache in cache (1)', path, value, _display_classname(self),
|
||||
id(self), index)
|
||||
@ -87,7 +87,7 @@ class Cache(DictCache):
|
||||
else:
|
||||
if DEBUG: # pragma: no cover
|
||||
print('getcache expired value for path {} < {}'.format(
|
||||
timestamp + expires_time, ntime))
|
||||
timestamp + expiration_time, ntime))
|
||||
# if expired, remove from cache
|
||||
#self.delcache(path)
|
||||
else:
|
||||
|
@ -18,7 +18,7 @@
|
||||
import weakref
|
||||
from typing import Optional
|
||||
from .error import ConfigError, PropertiesOptionError
|
||||
from .setting import owners, expires_time, undefined, forbidden_owners, OptionBag, ConfigBag
|
||||
from .setting import owners, undefined, forbidden_owners, OptionBag, ConfigBag
|
||||
from .autolib import carry_out_calculation
|
||||
from .i18n import _
|
||||
|
||||
@ -62,7 +62,7 @@ class Values(object):
|
||||
# try to retrive value in cache
|
||||
setting_properties = option_bag.config_bag.properties
|
||||
is_cached, value = self._p_.getcache(option_bag.path,
|
||||
expires_time,
|
||||
option_bag.config_bag.expiration_time,
|
||||
option_bag.index,
|
||||
setting_properties,
|
||||
option_bag.properties,
|
||||
|
Reference in New Issue
Block a user