Update cache size if storage->cache-size is changed.

This commit is contained in:
Florian Bruhin 2014-11-14 19:02:22 +01:00
parent 9bf776aee1
commit 3f6a40aac9

View File

@ -25,7 +25,7 @@ from PyQt5.QtCore import QStandardPaths
from PyQt5.QtNetwork import QNetworkDiskCache from PyQt5.QtNetwork import QNetworkDiskCache
from qutebrowser.config import config from qutebrowser.config import config
from qutebrowser.utils import utils, standarddir from qutebrowser.utils import utils, standarddir, objreg
class DiskCache(QNetworkDiskCache): class DiskCache(QNetworkDiskCache):
@ -37,8 +37,14 @@ class DiskCache(QNetworkDiskCache):
cache_dir = standarddir.get(QStandardPaths.CacheLocation) cache_dir = standarddir.get(QStandardPaths.CacheLocation)
self.setCacheDirectory(os.path.join(cache_dir, 'http')) self.setCacheDirectory(os.path.join(cache_dir, 'http'))
self.setMaximumCacheSize(config.get('storage', 'cache-size')) self.setMaximumCacheSize(config.get('storage', 'cache-size'))
objreg.get('config').changed.connect(self.cache_size_changed)
def __repr__(self): def __repr__(self):
return utils.get_repr(self, size=self.cacheSize(), return utils.get_repr(self, size=self.cacheSize(),
maxsize=self.maximumCacheSize(), maxsize=self.maximumCacheSize(),
path=self.cacheDirectory()) path=self.cacheDirectory())
@config.change_filter('storage', 'cache-size')
def cache_size_changed(self):
"""Update cache size if the config was changed."""
self.setMaximumCacheSize(config.get('storage', 'cache-size'))