Add a network disk cache.

This commit is contained in:
Florian Bruhin 2014-09-01 19:42:21 +02:00
parent 6d97da7bcc
commit 428d70c746
4 changed files with 54 additions and 7 deletions

View File

@ -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...")

View File

@ -0,0 +1,39 @@
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
#
# 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://www.gnu.org/licenses/>.
"""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'))

View File

@ -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(

View File

@ -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)