1/*
2 SPDX-FileCopyrightText: 2010 Grégory Oestreicher <greg@kamago.net>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef KDAV_ETAGCACHE_H
8#define KDAV_ETAGCACHE_H
9
10#include "kdav_export.h"
11
12#include <QObject>
13#include <QStringList>
14
15#include <memory>
16
17namespace KDAV
18{
19class EtagCachePrivate;
20
21/*!
22 * \class KDAV::EtagCache
23 * \inheaderfile KDAV/EtagCache
24 * \inmodule KDAV
25 *
26 * \brief A helper class to cache ETags.
27 *
28 * The EtagCache caches the remote ids and ETags of all items
29 * in a given collection. This cache is needed to find
30 * out which items have been changed in the backend and have to
31 * be refetched on the next call of Akonadi::ResourceBase::retrieveItems()
32 */
33class KDAV_EXPORT EtagCache : public QObject
34{
35 Q_OBJECT
36
37public:
38 /*!
39 * Creates a new ETag cache.
40 */
41 explicit EtagCache(QObject *parent = nullptr);
42 ~EtagCache() override;
43
44 /*!
45 * Sets the ETag for the remote ID. If the remote ID is marked as
46 * changed (is contained in the return of changedRemoteIds), remove
47 * it from the changed list.
48 */
49 void setEtag(const QString &remoteId, const QString &etag);
50
51 /*!
52 * Checks if the given item is in the cache
53 */
54 Q_REQUIRED_RESULT bool contains(const QString &remoteId) const;
55
56 /*!
57 * Check if the known ETag for the remote ID is equal to \a refEtag.
58 */
59 Q_REQUIRED_RESULT bool etagChanged(const QString &remoteId, const QString &refEtag) const;
60
61 /*!
62 * Mark an item as changed in the backend.
63 */
64 void markAsChanged(const QString &remoteId);
65
66 /*!
67 * Returns true if the remote ID is marked as changed (is contained in the
68 * return of changedRemoteIds)
69 */
70 Q_REQUIRED_RESULT bool isOutOfDate(const QString &remoteId) const;
71
72 /*!
73 * Removes the entry for item with remote ID \a remoteId.
74 */
75 void removeEtag(const QString &remoteId);
76
77 /*!
78 * Returns the list of all items URLs.
79 */
80 Q_REQUIRED_RESULT QStringList urls() const;
81
82 /*!
83 * Returns the list of remote ids of items that have been changed
84 * in the backend.
85 */
86 Q_REQUIRED_RESULT QStringList changedRemoteIds() const;
87
88protected:
89 /*!
90 * Sets the ETag for the remote ID.
91 */
92 void setEtagInternal(const QString &remoteId, const QString &etag);
93
94private:
95 const std::unique_ptr<EtagCachePrivate> d;
96
97 friend class DavItemsListJobPrivate;
98 // @internal
99 // Returns a map of remote Id and corresponding etag string key/value pairs.
100 // Only used by DavItemsListJobPrivate
101 Q_DECL_HIDDEN QMap<QString, QString> etagCacheMap() const;
102};
103}
104
105#endif
106

source code of kdav/src/common/etagcache.h