better cache

This commit is contained in:
2017-07-08 15:59:56 +02:00
parent 6bad3c6e64
commit dadf859905
21 changed files with 476 additions and 109 deletions

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
"sets the options of the configuration objects Config object itself"
# Copyright (C) 2012-2013 Team tiramisu (see AUTHORS for all contributors)
# Copyright (C) 2012-2017 Team tiramisu (see AUTHORS for all contributors)
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
@ -269,7 +269,7 @@ class Property(object):
raise ConfigError(_('cannot add those properties: {0}').format(propname))
self._properties.add(propname)
if save:
self._setting._setproperties(self._properties, self._path, force=True)
self._setting._setproperties(self._properties, self._opt, self._path, force=True)
def remove(self, propname):
"""Removes a property named propname
@ -279,7 +279,7 @@ class Property(object):
"""
if propname in self._properties:
self._properties.remove(propname)
self._setting._setproperties(self._properties, self._path)
self._setting._setproperties(self._properties, self._opt, self._path)
def extend(self, propnames):
"""Extends properties to the existing properties
@ -289,7 +289,7 @@ class Property(object):
"""
for propname in propnames:
self._append(propname, save=False)
self._setting._setproperties(self._properties, self._path)
self._setting._setproperties(self._properties, self._opt, self._path)
def reset(self):
"""resets the properties (does not **clear** the properties,
@ -370,7 +370,7 @@ class Settings(object):
if opt is not None and _path is None:
_path = opt.impl_getpath(self._getcontext())
self._p_.delproperties(_path)
self._getcontext().cfgimpl_reset_cache()
self._getcontext().cfgimpl_reset_cache(opt=opt, path=_path)
def _getproperties(self, opt=None, path=None,
setting_properties=undefined, read_write=True,
@ -415,20 +415,20 @@ class Settings(object):
props = self._p_.getproperties(None, default_properties)
if propname not in props:
props.add(propname)
self._setproperties(props, None)
self._setproperties(props, None, None)
def remove(self, propname):
"deletes property propname in the Config's properties attribute"
props = self._p_.getproperties(None, default_properties)
if propname in props:
props.remove(propname)
self._setproperties(props, None)
self._setproperties(props, None, None)
def extend(self, propnames):
for propname in propnames:
self.append(propname)
def _setproperties(self, properties, path, force=False):
def _setproperties(self, properties, opt, path, force=False):
"""save properties for specified path
(never save properties if same has option properties)
"""
@ -438,7 +438,7 @@ class Settings(object):
raise ConfigError(_('cannot add those properties: {0}').format(
' '.join(forbidden_properties)))
self._p_.setproperties(path, properties)
self._getcontext().cfgimpl_reset_cache()
self._getcontext().cfgimpl_reset_cache(opt=opt, path=path)
#____________________________________________________________
def validate_properties(self, opt_or_descr, is_descr, check_frozen, path,
@ -541,7 +541,7 @@ class Settings(object):
if not isinstance(permissive, tuple): # pragma: optional cover
raise TypeError(_('permissive must be a tuple'))
self._p_.setpermissive(path, permissive)
self._getcontext().cfgimpl_reset_cache()
self._getcontext().cfgimpl_reset_cache(opt=opt, path=path)
#____________________________________________________________
def setowner(self, owner):
@ -564,7 +564,7 @@ class Settings(object):
props = props | append
modified = True
if modified:
self._setproperties(props, None)
self._setproperties(props, None, None)
def read_only(self):
"convenience method to freeze, hide and disable"
@ -574,17 +574,6 @@ class Settings(object):
"convenience method to freeze, hide and disable"
self._read(rw_remove, rw_append)
def reset_cache(self, only_expired):
"""reset all settings in cache
:param only_expired: if True reset only expired cached values
:type only_expired: boolean
"""
if only_expired:
self._p_.reset_expired_cache(int(time()))
else:
self._p_.reset_all_cache()
def apply_requires(self, opt, path, setting_properties, index, debug):
"""carries out the jit (just in time) requirements between options