Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qnetworkdiskcache_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QNETWORKDISKCACHE_P_H
6#define QNETWORKDISKCACHE_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtNetwork/private/qtnetworkglobal_p.h>
20#include "private/qabstractnetworkcache_p.h"
21
22#include <qbuffer.h>
23#include <qhash.h>
24#include <qsavefile.h>
25
27
28QT_BEGIN_NAMESPACE
29
30class QCacheItem
31{
32public:
33 QCacheItem() = default;
34 ~QCacheItem()
35 {
36 reset();
37 }
38
39 QNetworkCacheMetaData metaData;
40 QBuffer data;
41 QSaveFile *file = nullptr;
42 inline qint64 size() const
43 { return file ? file->size() : data.size(); }
44
45 inline void reset() {
46 metaData = QNetworkCacheMetaData();
47 data.close();
48 delete file;
49 file = nullptr;
50 }
51 void writeHeader(QFileDevice *device) const;
52 void writeCompressedData(QFileDevice *device) const;
53 bool read(QFileDevice *device, bool readData);
54
55 bool canCompress() const;
56};
57
59{
60public:
66
67 static QString uniqueFileName(const QUrl &url);
68 QString cacheFileName(const QUrl &url) const;
69 bool removeFile(const QString &file);
70 void storeItem(QCacheItem *item);
71 void prepareLayout();
72 static quint32 crc32(const char *data, uint len);
73
74 mutable QCacheItem lastItem;
79
81 Q_DECLARE_PUBLIC(QNetworkDiskCache)
82};
83
84QT_END_NAMESPACE
85
86#endif // QNETWORKDISKCACHE_P_H
bool removeFile(const QString &file)
Put all of the misc file removing into one function to be extra safe.
QString cacheFileName(const QUrl &url) const
Generates fully qualified path of cached resource from a URL.
static QString uniqueFileName(const QUrl &url)
Given a URL, generates a unique enough filename (and subdirectory)
void prepareLayout()
Create subdirectories and other housekeeping on the filesystem.
QHash< QIODevice *, QCacheItem * > inserting
static quint32 crc32(const char *data, uint len)
void storeItem(QCacheItem *item)
The QNetworkDiskCache class provides a very basic disk cache.
QT_REQUIRE_CONFIG(animation)
#define CACHE_VERSION
#define DATA_DIR
#define CACHE_POSTFIX
@ CurrentCacheVersion
#define MAX_COMPRESSION_SIZE
QT_REQUIRE_CONFIG(networkdiskcache)