5#include "QtCore/qpointer.h"
6#include "QtCore/qdeadlinetimer.h"
52 qWarning() <<
"QNetworkAccessCache: object" << (
void*)
this <<
"key" <<
key
53 <<
"destroyed without being removed from cache first!";
81 (*it)->object->key.clear();
82 (*it)->object->dispose();
91 firstExpiringNode = lastExpiringNode =
nullptr;
104 Q_ASSERT(node != firstExpiringNode && node != lastExpiringNode);
105 Q_ASSERT(node->previous ==
nullptr && node->next ==
nullptr);
109 node->timer.setPreciseRemainingTime(node->object->expiryTimeoutSeconds);
110#ifdef DEBUG_ACCESSCACHE
112 << node->timer.remainingTime() <<
"milliseconds";
113 Node *current = lastExpiringNode;
116 << current->timer.remainingTime() <<
"milliseconds"
117 << (current == lastExpiringNode ?
"[last to expire]" :
"")
118 << (current == firstExpiringNode ?
"[first to expire]" :
"");
119 current = current->previous;
123 if (lastExpiringNode) {
125 if (lastExpiringNode->
timer < node->timer) {
127 node->previous = lastExpiringNode;
128 lastExpiringNode->
next = node;
129 lastExpiringNode = node;
132 Node *current = lastExpiringNode;
133 while (current->previous !=
nullptr && current->previous->timer >= node->timer)
134 current = current->previous;
135 node->previous = current->previous;
137 node->previous->next = node;
138 node->next = current;
139 current->previous = node;
140 if (node->previous ==
nullptr)
141 firstExpiringNode = node;
145 lastExpiringNode = node;
147 if (!firstExpiringNode) {
149 firstExpiringNode = node;
165 bool wasFirst =
false;
166 if (node == firstExpiringNode) {
167 firstExpiringNode = node->next;
170 if (node == lastExpiringNode)
171 lastExpiringNode = node->previous;
173 node->previous->next = node->next;
175 node->next->previous = node->previous;
177 node->next = node->previous =
nullptr;
181void QNetworkAccessCache::updateTimer()
185 if (!firstExpiringNode)
197 timer.
start(interval + 10,
this);
200bool QNetworkAccessCache::emitEntryReady(
Node *node,
QObject *
target,
const char *member)
218 delete firstExpiringNode;
219 firstExpiringNode =
next;
223 if (firstExpiringNode)
224 firstExpiringNode->
previous =
nullptr;
226 lastExpiringNode =
nullptr;
235 if (unlinkEntry(
key))
245 qWarning(
"QNetworkAccessCache::addEntry: overriding active cache entry '%s'",
key.constData());
250 if (connectionCacheExpiryTimeoutSeconds > -1) {
251 node->
object->expiryTimeoutSeconds = connectionCacheExpiryTimeoutSeconds;
273 if (node->
object->shareable) {
283 bool wasNext = unlinkEntry(
key);
295 qWarning(
"QNetworkAccessCache::releaseEntry: trying to release key '%s' that is not in cache",
key.constData());
303 if (node->
object->expires)
306 if (firstExpiringNode == node)
315 qWarning(
"QNetworkAccessCache::removeEntry: trying to remove key '%s' that is not in cache",
key.constData());
319 if (unlinkEntry(
key))
322 qWarning(
"QNetworkAccessCache::removeEntry: removing active cache entry '%s'",
332#include "moc_qnetworkaccesscache_p.cpp"
void start(int msec, QObject *obj)
\obsolete Use chrono overload instead.
void stop()
Stops the timer.
void clear()
Clears the contents of the byte array and makes it null.
bool hasExpired() const noexcept
Returns true if this QDeadlineTimer object has expired, false if there remains time left.
qint64 remainingTime() const noexcept
Returns the remaining time in this QDeadlineTimer object in milliseconds.
bool remove(const Key &key)
Removes the item that has the key from the hash.
iterator begin()
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in the hash.
iterator Iterator
Qt-style synonym for QHash::iterator.
bool contains(const Key &key) const noexcept
Returns true if the hash contains an item with the key; otherwise returns false.
T value(const Key &key) const noexcept
iterator end() noexcept
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last ...
void clear() noexcept(std::is_nothrow_destructible< Node >::value)
Removes all items from the hash and frees up all memory used by it.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
void setShareable(bool enable)
virtual ~CacheableObject()
void setExpires(bool enable)
bool hasEntry(const QByteArray &key) const
void removeEntry(const QByteArray &key)
CacheableObject * requestEntryNow(const QByteArray &key)
void addEntry(const QByteArray &key, CacheableObject *entry, qint64 connectionCacheExpiryTimeoutSeconds=-1)
void entryReady(QNetworkAccessCache::CacheableObject *)
void releaseEntry(const QByteArray &key)
void timerEvent(QTimerEvent *) override
This event handler can be reimplemented in a subclass to receive timer events for the object.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QSet< QString >::iterator it
Combined button and popup list for selecting options.
myObject disconnect()
[26]