Add an LRU cache to the config.

This commit is contained in:
Florian Bruhin 2014-08-27 20:16:04 +02:00
parent d2b744b195
commit 68ef9b97a3
2 changed files with 10 additions and 0 deletions

View File

@ -27,6 +27,7 @@ we borrow some methods and classes from there where it makes sense.
import os
import os.path
import textwrap
import functools
import configparser
import collections.abc
@ -277,6 +278,7 @@ class ConfigManager(QObject):
existed = optname in sectdict
if existed:
del sectdict[optname]
self.get.cache_clear()
return existed
@cmdutils.register(name='get', instance='config',
@ -301,6 +303,7 @@ class ConfigManager(QObject):
message.info("{} {} = {}".format(sectname, optname, val),
immediately=True)
@functools.lru_cache()
def get(self, sectname, optname, raw=False, transformed=True):
"""Get the value from a section/option.
@ -411,6 +414,7 @@ class ConfigManager(QObject):
if sectname in ('colors', 'fonts'):
self.style_changed.emit(sectname, optname)
self.changed.emit(sectname, optname)
self.get.cache_clear()
@cmdutils.register(instance='config')
def save(self):

View File

@ -29,6 +29,7 @@ from PyQt5.QtCore import pyqtRemoveInputHook, QEvent, QCoreApplication
from qutebrowser.utils import log, utils
from qutebrowser.commands import cmdutils
from qutebrowser.config import config
@cmdutils.register(debug=True, name='debug-set-trace')
@ -83,6 +84,11 @@ def debug_all_objects():
s = QCoreApplication.instance().get_all_objects()
log.misc.debug(s)
@cmdutils.register(debug=True)
def debug_cache_stats():
"""Print config LRU cache stats."""
info = config.instance().get.cache_info()
log.misc.debug(info)
def log_events(klass):
"""Class decorator to log Qt events."""