Add a network disk cache.
This commit is contained in:
parent
6d97da7bcc
commit
428d70c746
@ -39,7 +39,7 @@ from qutebrowser.commands import userscripts, runners, cmdutils
|
|||||||
from qutebrowser.config import (style, config, websettings, iniparsers,
|
from qutebrowser.config import (style, config, websettings, iniparsers,
|
||||||
lineparser, configtypes)
|
lineparser, configtypes)
|
||||||
from qutebrowser.network import qutescheme, proxy
|
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.widgets import mainwindow, console, crash
|
||||||
from qutebrowser.keyinput import modeparsers, keyparser, modeman
|
from qutebrowser.keyinput import modeparsers, keyparser, modeman
|
||||||
from qutebrowser.utils import (log, version, message, utilcmds, readline,
|
from qutebrowser.utils import (log, version, message, utilcmds, readline,
|
||||||
@ -62,6 +62,7 @@ class Application(QApplication):
|
|||||||
messagebridge: The global MessageBridge instance.
|
messagebridge: The global MessageBridge instance.
|
||||||
modeman: The global ModeManager instance.
|
modeman: The global ModeManager instance.
|
||||||
cookiejar: The global CookieJar instance.
|
cookiejar: The global CookieJar instance.
|
||||||
|
cache: The global DiskCache instance.
|
||||||
rl_bridge: The ReadlineBridge being used.
|
rl_bridge: The ReadlineBridge being used.
|
||||||
args: ArgumentParser instance.
|
args: ArgumentParser instance.
|
||||||
_keyparsers: A mapping from modes to keyparsers.
|
_keyparsers: A mapping from modes to keyparsers.
|
||||||
@ -127,6 +128,8 @@ class Application(QApplication):
|
|||||||
utilcmds.init()
|
utilcmds.init()
|
||||||
log.init.debug("Initializing cookies...")
|
log.init.debug("Initializing cookies...")
|
||||||
self.cookiejar = cookies.CookieJar(self)
|
self.cookiejar = cookies.CookieJar(self)
|
||||||
|
log.init.debug("Initializing cache...")
|
||||||
|
self.cache = cache.DiskCache(self)
|
||||||
log.init.debug("Initializing commands...")
|
log.init.debug("Initializing commands...")
|
||||||
self.commandrunner = runners.CommandRunner()
|
self.commandrunner = runners.CommandRunner()
|
||||||
log.init.debug("Initializing search...")
|
log.init.debug("Initializing search...")
|
||||||
|
39
qutebrowser/browser/cache.py
Normal file
39
qutebrowser/browser/cache.py
Normal 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'))
|
@ -479,6 +479,10 @@ DATA = collections.OrderedDict([
|
|||||||
('local-storage',
|
('local-storage',
|
||||||
SettingValue(typ.Bool(), 'true'),
|
SettingValue(typ.Bool(), 'true'),
|
||||||
"Whether support for the HTML 5 local storage feature is enabled."),
|
"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(
|
('permissions', sect.KeyValue(
|
||||||
|
@ -51,12 +51,13 @@ class NetworkManager(QNetworkAccessManager):
|
|||||||
self._scheme_handlers = {
|
self._scheme_handlers = {
|
||||||
'qute': qutescheme.QuteSchemeHandler(),
|
'qute': qutescheme.QuteSchemeHandler(),
|
||||||
}
|
}
|
||||||
cookiejar = QCoreApplication.instance().cookiejar
|
app = QCoreApplication.instance()
|
||||||
parent = cookiejar.parent()
|
self.setCookieJar(app.cookiejar)
|
||||||
self.setCookieJar(cookiejar)
|
self.setCache(app.cache)
|
||||||
# We have a shared cookie jar, so we don't want the NetworkManager to
|
# We have a shared cookie jar and cache , so we don't want the
|
||||||
# take ownership of the CookieJar.
|
# NetworkManager to take ownership of them.
|
||||||
cookiejar.setParent(parent)
|
app.cookiejar.setParent(app)
|
||||||
|
app.cache.setParent(app)
|
||||||
if SSL_AVAILABLE:
|
if SSL_AVAILABLE:
|
||||||
self.sslErrors.connect(self.on_ssl_errors)
|
self.sslErrors.connect(self.on_ssl_errors)
|
||||||
self.authenticationRequired.connect(self.on_authentication_required)
|
self.authenticationRequired.connect(self.on_authentication_required)
|
||||||
|
Loading…
Reference in New Issue
Block a user