diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 4733771ac..62718bedb 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -39,7 +39,7 @@ from qutebrowser.commands import userscripts, runners, cmdutils from qutebrowser.config import (style, config, websettings, iniparsers, lineparser, configtypes) from qutebrowser.network import qutescheme, proxy -from qutebrowser.browser import quickmarks, cookies, downloads +from qutebrowser.browser import quickmarks, cookies, downloads, cache from qutebrowser.widgets import mainwindow, console, crash from qutebrowser.keyinput import modeparsers, keyparser, modeman from qutebrowser.utils import (log, version, message, utilcmds, readline, @@ -62,6 +62,7 @@ class Application(QApplication): messagebridge: The global MessageBridge instance. modeman: The global ModeManager instance. cookiejar: The global CookieJar instance. + cache: The global DiskCache instance. rl_bridge: The ReadlineBridge being used. args: ArgumentParser instance. _keyparsers: A mapping from modes to keyparsers. @@ -127,6 +128,8 @@ class Application(QApplication): utilcmds.init() log.init.debug("Initializing cookies...") self.cookiejar = cookies.CookieJar(self) + log.init.debug("Initializing cache...") + self.cache = cache.DiskCache(self) log.init.debug("Initializing commands...") self.commandrunner = runners.CommandRunner() log.init.debug("Initializing search...") diff --git a/qutebrowser/browser/cache.py b/qutebrowser/browser/cache.py new file mode 100644 index 000000000..994e1dba0 --- /dev/null +++ b/qutebrowser/browser/cache.py @@ -0,0 +1,39 @@ +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + +# Copyright 2014 Florian Bruhin (The Compiler) +# +# This file is part of qutebrowser. +# +# qutebrowser is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# qutebrowser is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with qutebrowser. If not, see . + +"""HTTP network cache.""" + +import os.path + +from PyQt5.QtCore import QStandardPaths +from PyQt5.QtNetwork import QNetworkDiskCache + +from qutebrowser.config import config +from qutebrowser.utils import utils + + +class DiskCache(QNetworkDiskCache): + + """Disk cache which sets correct cache dir and size.""" + + def __init__(self, parent=None): + super().__init__(parent) + cache_dir = utils.get_standard_dir(QStandardPaths.CacheLocation) + self.setCacheDirectory(os.path.join(cache_dir, 'http')) + self.setMaximumCacheSize(config.get('storage', 'cache-size')) diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 20cf5291a..2c79bd209 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -479,6 +479,10 @@ DATA = collections.OrderedDict([ ('local-storage', SettingValue(typ.Bool(), 'true'), "Whether support for the HTML 5 local storage feature is enabled."), + + ('cache-size', + SettingValue(typ.Int(minval=0, maxval=MAXVALS['int64']), '52428800'), + "Size of the HTTP network cache."), )), ('permissions', sect.KeyValue( diff --git a/qutebrowser/network/networkmanager.py b/qutebrowser/network/networkmanager.py index 83f5563eb..d5e9be67b 100644 --- a/qutebrowser/network/networkmanager.py +++ b/qutebrowser/network/networkmanager.py @@ -51,12 +51,13 @@ class NetworkManager(QNetworkAccessManager): self._scheme_handlers = { 'qute': qutescheme.QuteSchemeHandler(), } - cookiejar = QCoreApplication.instance().cookiejar - parent = cookiejar.parent() - self.setCookieJar(cookiejar) - # We have a shared cookie jar, so we don't want the NetworkManager to - # take ownership of the CookieJar. - cookiejar.setParent(parent) + app = QCoreApplication.instance() + self.setCookieJar(app.cookiejar) + self.setCache(app.cache) + # We have a shared cookie jar and cache , so we don't want the + # NetworkManager to take ownership of them. + app.cookiejar.setParent(app) + app.cache.setParent(app) if SSL_AVAILABLE: self.sslErrors.connect(self.on_ssl_errors) self.authenticationRequired.connect(self.on_authentication_required)