Clean up cache.DiskCache.
This commit is contained in:
parent
0187dd6ac6
commit
764914a8b2
@ -426,7 +426,7 @@ def _init_modules(args, crash_handler):
|
|||||||
cookie_jar = cookies.CookieJar(qApp)
|
cookie_jar = cookies.CookieJar(qApp)
|
||||||
objreg.register('cookie-jar', cookie_jar)
|
objreg.register('cookie-jar', cookie_jar)
|
||||||
log.init.debug("Initializing cache...")
|
log.init.debug("Initializing cache...")
|
||||||
diskcache = cache.DiskCache(qApp)
|
diskcache = cache.DiskCache(standarddir.cache(), parent=qApp)
|
||||||
objreg.register('cache', diskcache)
|
objreg.register('cache', diskcache)
|
||||||
log.init.debug("Initializing completions...")
|
log.init.debug("Initializing completions...")
|
||||||
completionmodels.init()
|
completionmodels.init()
|
||||||
|
@ -34,16 +34,15 @@ class DiskCache(QNetworkDiskCache):
|
|||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
_activated: Whether the cache should be used.
|
_activated: Whether the cache should be used.
|
||||||
|
_cache_dir: The base directory for cache files (standarddir.cache())
|
||||||
|
_http_cache_dir: the HTTP subfolder in _cache_dir.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, cache_dir, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
cache_dir = standarddir.cache()
|
self._cache_dir = cache_dir
|
||||||
if config.get('general', 'private-browsing') or cache_dir is None:
|
self._http_cache_dir = os.path.join(cache_dir, 'http')
|
||||||
self._activated = False
|
self._maybe_activate()
|
||||||
else:
|
|
||||||
self._activated = True
|
|
||||||
self.setCacheDirectory(os.path.join(standarddir.cache(), 'http'))
|
|
||||||
self.setMaximumCacheSize(config.get('storage', 'cache-size'))
|
self.setMaximumCacheSize(config.get('storage', 'cache-size'))
|
||||||
objreg.get('config').changed.connect(self.on_config_changed)
|
objreg.get('config').changed.connect(self.on_config_changed)
|
||||||
|
|
||||||
@ -52,19 +51,22 @@ class DiskCache(QNetworkDiskCache):
|
|||||||
maxsize=self.maximumCacheSize(),
|
maxsize=self.maximumCacheSize(),
|
||||||
path=self.cacheDirectory())
|
path=self.cacheDirectory())
|
||||||
|
|
||||||
|
def _maybe_activate(self):
|
||||||
|
"""Activate/deactivate the cache based on the config."""
|
||||||
|
if (config.get('general', 'private-browsing') or
|
||||||
|
self._cache_dir is None):
|
||||||
|
self._activated = False
|
||||||
|
else:
|
||||||
|
self._activated = True
|
||||||
|
self.setCacheDirectory(self._http_cache_dir)
|
||||||
|
|
||||||
@pyqtSlot(str, str)
|
@pyqtSlot(str, str)
|
||||||
def on_config_changed(self, section, option):
|
def on_config_changed(self, section, option):
|
||||||
"""Update cache size/activated if the config was changed."""
|
"""Update cache size/activated if the config was changed."""
|
||||||
if (section, option) == ('storage', 'cache-size'):
|
if (section, option) == ('storage', 'cache-size'):
|
||||||
self.setMaximumCacheSize(config.get('storage', 'cache-size'))
|
self.setMaximumCacheSize(config.get('storage', 'cache-size'))
|
||||||
elif (section, option) == ('general', 'private-browsing'):
|
elif (section, option) == ('general', 'private-browsing'):
|
||||||
if (config.get('general', 'private-browsing') or
|
self._maybe_activate()
|
||||||
standarddir.cache() is None):
|
|
||||||
self._activated = False
|
|
||||||
else:
|
|
||||||
self._activated = True
|
|
||||||
self.setCacheDirectory(
|
|
||||||
os.path.join(standarddir.cache(), 'http'))
|
|
||||||
|
|
||||||
def cacheSize(self):
|
def cacheSize(self):
|
||||||
"""Return the current size taken up by the cache.
|
"""Return the current size taken up by the cache.
|
||||||
|
Loading…
Reference in New Issue
Block a user