KCoreAddons

kshareddatacache_win.cpp
1 /*
2  This file is part of the KDE project.
3 
4  SPDX-FileCopyrightText: 2010 Michael Pyne <[email protected]>
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 
20 class Q_DECL_HIDDEN KSharedDataCache::Private
21 {
22 public:
23  KSharedDataCache::EvictionPolicy evictionPolicy;
25 };
26 
27 KSharedDataCache::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 
36 KSharedDataCache::~KSharedDataCache()
37 {
38  delete d;
39 }
40 
41 KSharedDataCache::EvictionPolicy KSharedDataCache::evictionPolicy() const
42 {
43  return d->evictionPolicy;
44 }
45 
46 void KSharedDataCache::setEvictionPolicy(KSharedDataCache::EvictionPolicy newPolicy)
47 {
48  d->evictionPolicy = newPolicy;
49 }
50 
51 bool KSharedDataCache::insert(const QString &key, const QByteArray &data)
52 {
53  return d->cache.insert(key, new QByteArray(data));
54 }
55 
56 bool 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 
75 void KSharedDataCache::deleteCache(const QString &cacheName)
76 {
77  Q_UNUSED(cacheName);
78 }
79 
80 bool KSharedDataCache::contains(const QString &key) const
81 {
82  return d->cache.contains(key);
83 }
84 
85 unsigned KSharedDataCache::totalSize() const
86 {
87  return static_cast<unsigned>(d->cache.maxCost());
88 }
89 
90 unsigned 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 
99 unsigned KSharedDataCache::timestamp() const
100 {
101  return 0;
102 }
103 
104 void KSharedDataCache::setTimestamp(unsigned newTimestamp)
105 {
106 }
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 totalSize() const
Returns the usable cache size in bytes.
void setTimestamp(unsigned newTimestamp)
Sets the shared timestamp of the cache.
static void deleteCache(const QString &cacheName)
Removes the underlying file from the cache.
bool find(const QString &key, QByteArray *destination) const
Returns the data in the cache named by key (even if it&#39;s some other process&#39;s data named with the sam...
void clear()
Removes all entries from the cache.
A simple data cache which uses shared memory to quickly access data stored on disk.
unsigned timestamp() const
KSharedDataCache(const QString &cacheName, unsigned defaultCacheSize, unsigned expectedItemSize=0)
Attaches to a shared cache, creating it if necessary.
EvictionPolicy evictionPolicy() const
unsigned freeSize() const
Returns the amount of free space in the cache, in bytes.
void setEvictionPolicy(EvictionPolicy newPolicy)
Sets the entry removal policy for the shared cache to newPolicy.
bool contains(const QString &key) const
Returns true if the cache currently contains the image for the given filename.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Apr 18 2021 23:02:02 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.