KCoreAddons

kshareddatacache_win.cpp
1/*
2 This file is part of the KDE project.
3
4 SPDX-FileCopyrightText: 2010 Michael Pyne <mpyne@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-only
7*/
8
9/**
10 * This is a horrifically simple implementation of KSharedDataCache that is
11 * basically missing the "shared" part to it, for use on Windows or other platforms
12 * that don't support POSIX.
13 */
14#include "kshareddatacache.h"
15
16#include <QByteArray>
17#include <QCache>
18#include <QString>
19
20class Q_DECL_HIDDEN KSharedDataCache::Private
21{
22public:
23 KSharedDataCache::EvictionPolicy evictionPolicy;
25};
26
27KSharedDataCache::KSharedDataCache(const QString &cacheName, unsigned defaultCacheSize, unsigned expectedItemSize)
28 : d(new Private)
29{
30 d->cache.setMaxCost(defaultCacheSize);
31
32 Q_UNUSED(cacheName);
33 Q_UNUSED(expectedItemSize);
34}
35
36KSharedDataCache::~KSharedDataCache()
37{
38 delete d;
39}
40
41KSharedDataCache::EvictionPolicy KSharedDataCache::evictionPolicy() const
42{
43 return d->evictionPolicy;
44}
45
46void KSharedDataCache::setEvictionPolicy(KSharedDataCache::EvictionPolicy newPolicy)
47{
48 d->evictionPolicy = newPolicy;
49}
50
51bool KSharedDataCache::insert(const QString &key, const QByteArray &data)
52{
53 return d->cache.insert(key, new QByteArray(data));
54}
55
56bool KSharedDataCache::find(const QString &key, QByteArray *destination) const
57{
58 QByteArray *value = d->cache.object(key);
59
60 if (value) {
61 if (destination) {
62 *destination = *value;
63 }
64 return true;
65 } else {
66 return false;
67 }
68}
69
71{
72 d->cache.clear();
73}
74
75void KSharedDataCache::deleteCache(const QString &cacheName)
76{
77 Q_UNUSED(cacheName);
78}
79
80bool KSharedDataCache::contains(const QString &key) const
81{
82 return d->cache.contains(key);
83}
84
85unsigned KSharedDataCache::totalSize() const
86{
87 return static_cast<unsigned>(d->cache.maxCost());
88}
89
90unsigned KSharedDataCache::freeSize() const
91{
92 if (d->cache.totalCost() < d->cache.maxCost()) {
93 return static_cast<unsigned>(d->cache.maxCost() - d->cache.totalCost());
94 } else {
95 return 0;
96 }
97}
98
99unsigned KSharedDataCache::timestamp() const
100{
101 return 0;
102}
103
104void KSharedDataCache::setTimestamp(unsigned newTimestamp)
105{
106 Q_UNUSED(newTimestamp);
107}
A simple data cache which uses shared memory to quickly access data stored on disk.
unsigned freeSize() const
Returns the amount of free space in the cache, in bytes.
static void deleteCache(const QString &cacheName)
Removes the underlying file from the cache.
void clear()
Removes all entries from the cache.
unsigned totalSize() const
Returns the usable cache size in bytes.
void setEvictionPolicy(EvictionPolicy newPolicy)
Sets the entry removal policy for the shared cache to newPolicy.
KSharedDataCache(const QString &cacheName, unsigned defaultCacheSize, unsigned expectedItemSize=0)
Attaches to a shared cache, creating it if necessary.
bool insert(const QString &key, const QByteArray &data)
Attempts to insert the entry data into the shared cache, named by key, and returns true only if succe...
unsigned timestamp() const
bool contains(const QString &key) const
Returns true if the cache currently contains the image for the given filename.
EvictionPolicy evictionPolicy() const
void setTimestamp(unsigned newTimestamp)
Sets the shared timestamp of the cache.
bool find(const QString &key, QByteArray *destination) const
Returns the data in the cache named by key (even if it's some other process's data named with the sam...
void clear()
bool contains(const Key &key) const const
bool insert(const Key &key, T *object, qsizetype cost)
qsizetype maxCost() const const
T * object(const Key &key) const const
qsizetype totalCost() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:24 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.