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 
14 #include "kshareddatacache.h"
15 
16 #include <QString>
17 #include <QByteArray>
18 #include <QCache>
19 
20 class Q_DECL_HIDDEN KSharedDataCache::Private
21 {
22 public:
23  KSharedDataCache::EvictionPolicy evictionPolicy;
25 };
26 
28  unsigned defaultCacheSize,
29  unsigned expectedItemSize)
30  : d(new Private)
31 {
32  d->cache.setMaxCost(defaultCacheSize);
33 
34  Q_UNUSED(cacheName);
35  Q_UNUSED(expectedItemSize);
36 }
37 
38 KSharedDataCache::~KSharedDataCache()
39 {
40  delete d;
41 }
42 
43 KSharedDataCache::EvictionPolicy KSharedDataCache::evictionPolicy() const
44 {
45  return d->evictionPolicy;
46 }
47 
48 void KSharedDataCache::setEvictionPolicy(KSharedDataCache::EvictionPolicy newPolicy)
49 {
50  d->evictionPolicy = newPolicy;
51 }
52 
53 bool KSharedDataCache::insert(const QString &key, const QByteArray &data)
54 {
55  return d->cache.insert(key, new QByteArray(data));
56 }
57 
58 bool KSharedDataCache::find(const QString &key, QByteArray *destination) const
59 {
60  QByteArray *value = d->cache.object(key);
61 
62  if (value) {
63  if (destination) {
64  *destination = *value;
65  }
66  return true;
67  } else {
68  return false;
69  }
70 }
71 
73 {
74  d->cache.clear();
75 }
76 
77 void KSharedDataCache::deleteCache(const QString &cacheName)
78 {
79  Q_UNUSED(cacheName);
80 }
81 
82 bool KSharedDataCache::contains(const QString &key) const
83 {
84  return d->cache.contains(key);
85 }
86 
87 unsigned KSharedDataCache::totalSize() const
88 {
89  return static_cast<unsigned>(d->cache.maxCost());
90 }
91 
92 unsigned KSharedDataCache::freeSize() const
93 {
94  if (d->cache.totalCost() < d->cache.maxCost()) {
95  return static_cast<unsigned>(d->cache.maxCost() - d->cache.totalCost());
96  } else {
97  return 0;
98  }
99 }
100 
101 unsigned KSharedDataCache::timestamp() const
102 {
103  return 0;
104 }
105 
106 void KSharedDataCache::setTimestamp(unsigned newTimestamp)
107 {
108 }
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-2020 The KDE developers.
Generated on Thu Jul 9 2020 23:01:14 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.