![]() |
CopperSpice API
1.7.4
|
The QNetworkDiskCache class provides a very basic disk cache. More...
Public Slots | |
void | clear () |
![]() | |
virtual void | clear () |
![]() | |
void | deleteLater () |
Public Methods | |
QNetworkDiskCache (QObject *parent=nullptr) | |
~QNetworkDiskCache () | |
QString | cacheDirectory () const |
qint64 | cacheSize () const override |
QIODevice * | data (const QUrl &url) override |
QNetworkCacheMetaData | fileMetaData (const QString &fileName) const |
void | insert (QIODevice *device) override |
qint64 | maximumCacheSize () const |
QNetworkCacheMetaData | metaData (const QUrl &url) override |
QIODevice * | prepare (const QNetworkCacheMetaData &metaData) override |
bool | remove (const QUrl &url) override |
void | setCacheDirectory (const QString &cacheDir) |
void | setMaximumCacheSize (qint64 size) |
void | updateMetaData (const QNetworkCacheMetaData &metaData) override |
![]() | |
virtual | ~QAbstractNetworkCache () |
![]() | |
QObject (QObject *parent=nullptr) | |
~QObject () | |
bool | blockSignals (bool block) |
const QList< QObject * > & | children () const |
bool | connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
bool | connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
bool | disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const |
bool | disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const |
bool | disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const |
void | dumpObjectInfo () |
void | dumpObjectTree () |
QList< QString > | dynamicPropertyNames () const |
virtual bool | event (QEvent *event) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
template<typename T > | |
T | findChild (const QString &childName=QString ()) const |
template<class T > | |
QList< T > | findChildren (const QRegularExpression ®Exp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
template<class T > | |
QList< T > | findChildren (const QString &objName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
bool | inherits (const QString &className) const |
void | installEventFilter (QObject *filterObj) |
bool | isWidgetType () const |
bool | isWindowType () const |
void | killTimer (int id) |
const QMetaObject * | metaObject () const |
void | moveToThread (QThread *targetThread) |
QString | objectName () const |
QObject * | parent () const |
template<class T = QVariant> | |
T | property (const QString &name) const |
void | removeEventFilter (QObject *obj) |
void | setObjectName (const QString &name) |
void | setParent (QObject *parent) |
bool | setProperty (const QString &name, const QVariant &value) |
bool | signalsBlocked () const |
int | startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer) |
QThread * | thread () const |
Protected Methods | |
virtual qint64 | expire () |
![]() | |
QAbstractNetworkCache (QObject *parent=nullptr) | |
![]() | |
virtual void | childEvent (QChildEvent *event) |
virtual void | connectNotify (const QMetaMethod &signalMethod) const |
virtual void | customEvent (QEvent *event) |
virtual void | disconnectNotify (const QMetaMethod &signalMethod) const |
bool | isSignalConnected (const QMetaMethod &signalMethod) const |
int | receivers (const QString &signal) const |
QObject * | sender () const |
int | senderSignalIndex () const |
virtual void | timerEvent (QTimerEvent *event) |
Additional Inherited Members | |
![]() | |
void | destroyed (QObject *obj=nullptr) |
void | objectNameChanged (const QString &objectName) |
![]() | |
static bool | connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ()) |
static bool | connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn > | |
static bool | connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T > | |
static bool | connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod) |
static bool | disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod) |
static bool | disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod) |
static bool | disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...)) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod) |
static QMetaObject & | staticMetaObject () |
static QString | tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >()) |
![]() | |
objectName | |
![]() | |
T | qobject_cast (QObject *object) |
QObjectList | |
The QNetworkDiskCache class provides a very basic disk cache.
QNetworkDiskCache stores each url in its own file inside of the cacheDirectory using QDataStream. Files with a text MimeType are compressed using qCompress. Each cache file starts with "cache_" and ends in ".cache". Data is written to disk only in insert() and updateMetaData().
Currently you can not share the same cache files with more then one disk cache.
QNetworkDiskCache by default limits the amount of space that the cache will use on the system to 50MB.
Note you have to set the cache directory before it will work.
A network disk cache can be enabled by:
When sending requests, to control the preference of when to use the cache and when to use the network, consider the following:
To check whether the response came from the cache or from the network, the following can be applied:
|
explicit |
Creates a new disk cache. The parent argument is passed to QAbstractNetworkCache's constructor.
QNetworkDiskCache::~QNetworkDiskCache | ( | ) |
Destroys the cache object. This does not clear the disk cache.
QString QNetworkDiskCache::cacheDirectory | ( | ) | const |
Returns the location where cached files will be stored.
|
overridevirtual |
Reimplemented from QAbstractNetworkCache::cacheSize().
Implements QAbstractNetworkCache.
|
slot |
Reimplemented from QAbstractNetworkCache::clear().
Reimplemented from QAbstractNetworkCache::data().
Implements QAbstractNetworkCache.
|
protectedvirtual |
Cleans the cache so that its size is under the maximum cache size. Returns the current size of the cache.
When the current size of the cache is greater than the maximumCacheSize() older cache files are removed until the total size is less then 90% of maximumCacheSize() starting with the oldest ones first using the file creation date to determine how old a cache file is.
Subclasses can reimplement this function to change the order that cache files are removed taking into account information in the application knows about that QNetworkDiskCache does not, for example the number of times a cache is accessed.
Note: cacheSize() calls expire if the current cache size is unknown.
QNetworkCacheMetaData QNetworkDiskCache::fileMetaData | ( | const QString & | fileName | ) | const |
Returns the QNetworkCacheMetaData for the cache file fileName.
If fileName is not a cache file QNetworkCacheMetaData will be invalid.
|
overridevirtual |
Reimplemented from QAbstractNetworkCache::insert().
Implements QAbstractNetworkCache.
qint64 QNetworkDiskCache::maximumCacheSize | ( | ) | const |
Returns the current maximum size in bytes for the disk cache.
|
overridevirtual |
Reimplemented from QAbstractNetworkCache::metaData().
Implements QAbstractNetworkCache.
|
overridevirtual |
Reimplemented from QAbstractNetworkCache::prepare().
Implements QAbstractNetworkCache.
|
overridevirtual |
Reimplemented from QAbstractNetworkCache::remove().
Implements QAbstractNetworkCache.
void QNetworkDiskCache::setCacheDirectory | ( | const QString & | cacheDir | ) |
Sets the directory where cached files will be stored to cacheDir
QNetworkDiskCache will create this directory if it does not exists.
Prepared cache items will be stored in the new cache directory when they are inserted.
void QNetworkDiskCache::setMaximumCacheSize | ( | qint64 | size | ) |
Sets the maximum size of the disk cache to be size in bytes.
If the new size is smaller then the current cache size then the cache will call expire().
|
overridevirtual |
Reimplemented from QAbstractNetworkCache::updateMetaData().
Implements QAbstractNetworkCache.