• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDECore

  • kdecore
  • util
kshareddatacache_win.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the KDE project.
3 * Copyright © 2010 Michael Pyne <mpyne@kde.org>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License version 2 as published by the Free Software Foundation.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
25#include "kshareddatacache.h"
26
27#include <QtCore/QString>
28#include <QtCore/QByteArray>
29#include <QtCore/QCache>
30
31class KSharedDataCache::Private
32{
33 public:
34 KSharedDataCache::EvictionPolicy evictionPolicy;
35 QCache<QString, QByteArray> cache;
36};
37
38KSharedDataCache::KSharedDataCache(const QString &cacheName,
39 unsigned defaultCacheSize,
40 unsigned expectedItemSize)
41 : d(new Private)
42{
43 d->cache.setMaxCost(defaultCacheSize);
44
45 Q_UNUSED(cacheName);
46 Q_UNUSED(expectedItemSize);
47}
48
49KSharedDataCache::~KSharedDataCache()
50{
51 delete d;
52}
53
54KSharedDataCache::EvictionPolicy KSharedDataCache::evictionPolicy() const
55{
56 return d->evictionPolicy;
57}
58
59void KSharedDataCache::setEvictionPolicy(KSharedDataCache::EvictionPolicy newPolicy)
60{
61 d->evictionPolicy = newPolicy;
62}
63
64bool KSharedDataCache::insert(const QString &key, const QByteArray &data)
65{
66 return d->cache.insert(key, new QByteArray(data));
67}
68
69bool KSharedDataCache::find(const QString &key, QByteArray *destination) const
70{
71 QByteArray *value = d->cache.object(key);
72
73 if (value) {
74 destination = value;
75 return true;
76 }
77 else {
78 return false;
79 }
80}
81
82void KSharedDataCache::clear()
83{
84 d->cache.clear();
85}
86
87void KSharedDataCache::deleteCache(const QString &cacheName)
88{
89 Q_UNUSED(cacheName);
90}
91
92bool KSharedDataCache::contains(const QString &key) const
93{
94 return d->cache.contains(key);
95}
96
97unsigned KSharedDataCache::totalSize() const
98{
99 return static_cast<unsigned>(d->cache.maxCost());
100}
101
102unsigned KSharedDataCache::freeSize() const
103{
104 if (d->cache.totalCost() < d->cache.maxCost()) {
105 return static_cast<unsigned>(d->cache.maxCost() - d->cache.totalCost());
106 }
107 else {
108 return 0;
109 }
110}
111
112unsigned KSharedDataCache::timestamp() const
113{
114 return 0;
115}
116
117void KSharedDataCache::setTimestamp(unsigned newTimestamp)
118{
119}
KSharedDataCache::EvictionPolicy
EvictionPolicy
Definition: kshareddatacache.h:84
KSharedDataCache::freeSize
unsigned freeSize() const
Returns the amount of free space in the cache, in bytes.
Definition: kshareddatacache.cpp:1704
KSharedDataCache::deleteCache
static void deleteCache(const QString &cacheName)
Removes the underlying file from the cache.
Definition: kshareddatacache.cpp:1677
KSharedDataCache::clear
void clear()
Removes all entries from the cache.
Definition: kshareddatacache.cpp:1647
KSharedDataCache::~KSharedDataCache
~KSharedDataCache()
Definition: kshareddatacache.cpp:1422
KSharedDataCache::totalSize
unsigned totalSize() const
Returns the usable cache size in bytes.
Definition: kshareddatacache.cpp:1688
KSharedDataCache::setEvictionPolicy
void setEvictionPolicy(EvictionPolicy newPolicy)
Sets the entry removal policy for the shared cache to newPolicy.
Definition: kshareddatacache.cpp:1729
KSharedDataCache::KSharedDataCache
KSharedDataCache(const QString &cacheName, unsigned defaultCacheSize, unsigned expectedItemSize=0)
Attaches to a shared cache, creating it if necessary.
Definition: kshareddatacache.cpp:1398
KSharedDataCache::insert
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...
Definition: kshareddatacache.cpp:1444
KSharedDataCache::timestamp
unsigned timestamp() const
Definition: kshareddatacache.cpp:1736
KSharedDataCache::contains
bool contains(const QString &key) const
Returns true if the cache currently contains the image for the given filename.
Definition: kshareddatacache.cpp:1661
KSharedDataCache::evictionPolicy
EvictionPolicy evictionPolicy() const
Definition: kshareddatacache.cpp:1720
KSharedDataCache::setTimestamp
void setTimestamp(unsigned newTimestamp)
Sets the shared timestamp of the cache.
Definition: kshareddatacache.cpp:1745
KSharedDataCache::find
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...
Definition: kshareddatacache.cpp:1603
QString
kshareddatacache.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal