1/*
2 SPDX-FileCopyrightText: 2010 Grégory Oestreicher <greg@kamago.net>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "etagcache.h"
8
9#include <QMap>
10#include <QSet>
11
12using namespace KDAV;
13
14namespace KDAV
15{
16class EtagCachePrivate
17{
18public:
19 QMap<QString, QString> mCache;
20 QSet<QString> mChangedRemoteIds;
21};
22}
23
24EtagCache::EtagCache(QObject *parent)
25 : QObject(parent)
26 , d(new EtagCachePrivate)
27{
28}
29
30EtagCache::~EtagCache() = default;
31
32void EtagCache::setEtag(const QString &remoteId, const QString &etag)
33{
34 setEtagInternal(remoteId, etag);
35
36 d->mChangedRemoteIds.remove(value: remoteId);
37}
38
39void EtagCache::setEtagInternal(const QString &remoteId, const QString &etag)
40{
41 d->mCache[remoteId] = etag;
42}
43
44bool EtagCache::contains(const QString &remoteId) const
45{
46 return d->mCache.contains(key: remoteId);
47}
48
49bool EtagCache::etagChanged(const QString &remoteId, const QString &refEtag) const
50{
51 if (!contains(remoteId)) {
52 return true;
53 }
54 return d->mCache.value(key: remoteId) != refEtag;
55}
56
57void EtagCache::markAsChanged(const QString &remoteId)
58{
59 d->mChangedRemoteIds.insert(value: remoteId);
60}
61
62bool EtagCache::isOutOfDate(const QString &remoteId) const
63{
64 return d->mChangedRemoteIds.contains(value: remoteId);
65}
66
67void EtagCache::removeEtag(const QString &remoteId)
68{
69 d->mChangedRemoteIds.remove(value: remoteId);
70 d->mCache.remove(key: remoteId);
71}
72
73QMap<QString, QString> EtagCache::etagCacheMap() const
74{
75 return d->mCache;
76}
77
78QStringList EtagCache::urls() const
79{
80 return d->mCache.keys();
81}
82
83QStringList EtagCache::changedRemoteIds() const
84{
85 return d->mChangedRemoteIds.values();
86}
87
88#include "moc_etagcache.cpp"
89

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