mirror of https://github.com/vitalif/phantomjs
Config to limit the disk cache size.
Based on the previous patch at https://github.com/ariya/phantomjs/pull/144. http://code.google.com/p/phantomjs/issues/detail?id=2201.3
parent
7aa5ec5347
commit
cebe64ec31
|
@ -84,6 +84,10 @@ void Config::processArgs(const QStringList &args)
|
|||
setDiskCacheEnabled(false);
|
||||
continue;
|
||||
}
|
||||
if (arg.startsWith("--max-disk-cache-size=")) {
|
||||
setMaxDiskCacheSize(arg.mid(arg.indexOf("=") + 1).trimmed().toInt());
|
||||
continue;
|
||||
}
|
||||
if (arg == "--ignore-ssl-errors=yes") {
|
||||
setIgnoreSslErrors(true);
|
||||
continue;
|
||||
|
@ -208,6 +212,16 @@ void Config::setDiskCacheEnabled(const bool value)
|
|||
m_diskCacheEnabled = value;
|
||||
}
|
||||
|
||||
int Config::maxDiskCacheSize() const
|
||||
{
|
||||
return m_maxDiskCacheSize;
|
||||
}
|
||||
|
||||
void Config::setMaxDiskCacheSize(int maxDiskCacheSize)
|
||||
{
|
||||
m_maxDiskCacheSize = maxDiskCacheSize;
|
||||
}
|
||||
|
||||
bool Config::ignoreSslErrors() const
|
||||
{
|
||||
return m_ignoreSslErrors;
|
||||
|
@ -379,6 +393,7 @@ void Config::resetToDefaults()
|
|||
m_autoLoadImages = true;
|
||||
m_cookieFile.clear();
|
||||
m_diskCacheEnabled = false;
|
||||
m_maxDiskCacheSize = -1;
|
||||
m_ignoreSslErrors = false;
|
||||
m_localAccessRemote = false;
|
||||
m_outputEncoding = "UTF-8";
|
||||
|
|
|
@ -39,6 +39,7 @@ class Config: QObject
|
|||
Q_OBJECT
|
||||
Q_PROPERTY(QString cookieFile READ cookieFile WRITE setCookieFile)
|
||||
Q_PROPERTY(bool diskCacheEnabled READ diskCacheEnabled WRITE setDiskCacheEnabled)
|
||||
Q_PROPERTY(int maxDiskCacheSize READ maxDiskCacheSize WRITE setMaxDiskCacheSize)
|
||||
Q_PROPERTY(bool ignoreSslErrors READ ignoreSslErrors WRITE setIgnoreSslErrors)
|
||||
Q_PROPERTY(bool localAccessRemote READ localAccessRemote WRITE setLocalAccessRemote)
|
||||
Q_PROPERTY(QString outputEncoding READ outputEncoding WRITE setOutputEncoding)
|
||||
|
@ -63,6 +64,9 @@ public:
|
|||
bool diskCacheEnabled() const;
|
||||
void setDiskCacheEnabled(const bool value);
|
||||
|
||||
int maxDiskCacheSize() const;
|
||||
void setMaxDiskCacheSize(int maxDiskCacheSize);
|
||||
|
||||
bool ignoreSslErrors() const;
|
||||
void setIgnoreSslErrors(const bool value);
|
||||
|
||||
|
@ -110,6 +114,7 @@ private:
|
|||
bool m_autoLoadImages;
|
||||
QString m_cookieFile;
|
||||
bool m_diskCacheEnabled;
|
||||
int m_maxDiskCacheSize;
|
||||
bool m_ignoreSslErrors;
|
||||
bool m_localAccessRemote;
|
||||
QString m_outputEncoding;
|
||||
|
|
|
@ -67,7 +67,7 @@ static const char *toString(QNetworkAccessManager::Operation op)
|
|||
}
|
||||
|
||||
// public:
|
||||
NetworkAccessManager::NetworkAccessManager(QObject *parent, bool diskCacheEnabled, QString cookieFile, bool ignoreSslErrors, QString authUser, QString authPass)
|
||||
NetworkAccessManager::NetworkAccessManager(QObject *parent, bool diskCacheEnabled, QString cookieFile, bool ignoreSslErrors, QString authUser, QString authPass, int maxCacheSize)
|
||||
: QNetworkAccessManager(parent)
|
||||
, m_networkDiskCache(0)
|
||||
, m_ignoreSslErrors(ignoreSslErrors)
|
||||
|
@ -82,6 +82,8 @@ NetworkAccessManager::NetworkAccessManager(QObject *parent, bool diskCacheEnable
|
|||
if (diskCacheEnabled) {
|
||||
m_networkDiskCache = new QNetworkDiskCache();
|
||||
m_networkDiskCache->setCacheDirectory(QDesktopServices::storageLocation(QDesktopServices::CacheLocation));
|
||||
if (maxCacheSize >= 0)
|
||||
m_networkDiskCache->setMaximumCacheSize(maxCacheSize * 1024);
|
||||
setCache(m_networkDiskCache);
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,8 @@ class NetworkAccessManager : public QNetworkAccessManager
|
|||
public:
|
||||
NetworkAccessManager(QObject *parent = 0, bool diskCacheEnabled = false,
|
||||
QString cookieFile = QString(), bool ignoreSslErrors = false,
|
||||
QString authUser = QString(), QString authPass = QString());
|
||||
QString authUser = QString(), QString authPass = QString(),
|
||||
int maxCacheSize = -1);
|
||||
virtual ~NetworkAccessManager();
|
||||
|
||||
protected:
|
||||
|
|
|
@ -91,7 +91,8 @@ Phantom::Phantom(QObject *parent)
|
|||
m_scriptFileEnc.setEncoding(m_config.scriptEncoding());
|
||||
|
||||
// Provide WebPage with a non-standard Network Access Manager
|
||||
m_netAccessMan = new NetworkAccessManager(this, m_config.diskCacheEnabled(), m_config.cookieFile(), m_config.ignoreSslErrors(), m_config.authUser(), m_config.authPass());
|
||||
m_netAccessMan = new NetworkAccessManager(this, m_config.diskCacheEnabled(),
|
||||
m_config.cookieFile(), m_config.ignoreSslErrors(), m_config.authUser(), m_config.authPass(), m_config.maxDiskCacheSize());
|
||||
m_page->setNetworkAccessManager(m_netAccessMan);
|
||||
|
||||
connect(m_page, SIGNAL(javaScriptConsoleMessageSent(QString, int, QString)),
|
||||
|
|
|
@ -9,6 +9,7 @@ Options:
|
|||
--proxy=address:port Sets the network proxy (e.g. "--proxy=http://192.168.1.42:8080").
|
||||
--auth=username:password Sets the authentication username and password (e.g. "--auth=username:password").
|
||||
--disk-cache=[yes|no] Enables disk cache (at desktop services cache storage location, default is 'no').
|
||||
--max-disk-cache-size=size Limits the size of disk cache (in KB).
|
||||
--ignore-ssl-errors=[yes|no] Ignores SSL errors (i.e. expired or self-signed certificate errors).
|
||||
--local-access-remote=[yes|no] Local content can access remote URL (default is 'no').
|
||||
--output-encoding Sets (if available) the encoding used for terminal output (default is 'utf8').
|
||||
|
|
Loading…
Reference in New Issue