KDAV

etagcache.h
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 EtagCache etagcache.h <KDAV/EtagCache>
23 *
24 * @short A helper class to cache ETags.
25 *
26 * The EtagCache caches the remote ids and ETags of all items
27 * in a given collection. This cache is needed to find
28 * out which items have been changed in the backend and have to
29 * be refetched on the next call of Akonadi::ResourceBase::retrieveItems()
30 */
31class KDAV_EXPORT EtagCache : public QObject
32{
33 Q_OBJECT
34
35public:
36 /**
37 * Creates a new ETag cache and populates it with the ETags
38 * of items found in @p collection.
39 */
40 explicit EtagCache(QObject *parent = nullptr);
41 ~EtagCache() override;
42
43 /**
44 * Sets the ETag for the remote ID. If the remote ID is marked as
45 * changed (is contained in the return of changedRemoteIds), remove
46 * it from the changed list.
47 */
48 void setEtag(const QString &remoteId, const QString &etag);
49
50 /**
51 * Checks if the given item is in the cache
52 */
53 Q_REQUIRED_RESULT bool contains(const QString &remoteId) const;
54
55 /**
56 * Check if the known ETag for the remote ID is equal to @p refEtag.
57 */
58 Q_REQUIRED_RESULT bool etagChanged(const QString &remoteId, const QString &refEtag) const;
59
60 /**
61 * Mark an item as changed in the backend.
62 */
63 void markAsChanged(const QString &remoteId);
64
65 /**
66 * Returns true if the remote ID is marked as changed (is contained in the
67 * return of changedRemoteIds)
68 */
69 Q_REQUIRED_RESULT bool isOutOfDate(const QString &remoteId) const;
70
71 /**
72 * Removes the entry for item with remote ID @p remoteId.
73 */
74 void removeEtag(const QString &remoteId);
75
76 /**
77 * Returns the list of all items URLs.
78 */
79 Q_REQUIRED_RESULT QStringList urls() const;
80
81 /**
82 * Returns the list of remote ids of items that have been changed
83 * in the backend.
84 */
85 Q_REQUIRED_RESULT QStringList changedRemoteIds() const;
86
87protected:
88 /**
89 * Sets the ETag for the remote ID.
90 */
91 void setEtagInternal(const QString &remoteId, const QString &etag);
92
93private:
94 const std::unique_ptr<EtagCachePrivate> d;
95
96 friend class DavItemsListJobPrivate;
97 // @internal
98 // Returns a map of remote Id and corresponding etag string key/value pairs.
99 // Only used by DavItemsListJobPrivate
100 Q_DECL_HIDDEN QMap<QString, QString> etagCacheMap() const;
101};
102}
103
104#endif
A helper class to cache ETags.
Definition etagcache.h:32
The KDAV namespace.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:16:34 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.