KDECore
kshareddatacache.h
Go to the documentation of this file.
00001 /* 00002 * This file is part of the KDE project. 00003 * Copyright © 2010 Michael Pyne <mpyne@kde.org> 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Library General Public 00007 * License version 2 as published by the Free Software Foundation. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Library General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Library General Public License 00015 * along with this library; see the file COPYING.LIB. If not, write to 00016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 * Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #ifndef KSHAREDDATACACHE_H 00021 #define KSHAREDDATACACHE_H 00022 00023 #include <kdecore_export.h> 00024 00025 class QString; 00026 class QByteArray; 00027 00058 class KDECORE_EXPORT KSharedDataCache 00059 { 00060 public: 00078 KSharedDataCache(const QString &cacheName, 00079 unsigned defaultCacheSize, 00080 unsigned expectedItemSize = 0); 00081 ~KSharedDataCache(); 00082 00083 enum EvictionPolicy 00084 { 00085 // The default value for data in our shared memory will be 0, so it is 00086 // important that whatever we want for the default value is also 0. 00087 NoEvictionPreference = 0, 00088 EvictLeastRecentlyUsed, 00089 EvictLeastOftenUsed, 00090 EvictOldest 00091 }; 00092 00097 EvictionPolicy evictionPolicy() const; 00098 00105 void setEvictionPolicy(EvictionPolicy newPolicy); 00106 00114 bool insert(const QString &key, const QByteArray &data); 00115 00132 bool find(const QString &key, QByteArray *destination) const; 00133 00137 void clear(); 00138 00146 static void deleteCache(const QString &cacheName); 00147 00156 bool contains(const QString &key) const; 00157 00163 unsigned totalSize() const; 00164 00171 unsigned freeSize() const; 00172 00182 unsigned timestamp() const; 00183 00215 void setTimestamp(unsigned newTimestamp); 00216 00217 private: 00218 class Private; 00219 Private *d; 00220 }; 00221 00222 #endif
KDE 4.6 API Reference