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

KDECore

kshareddatacache_win.cpp

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 
00025 #include "kshareddatacache.h"
00026 
00027 #include <QtCore/QString>
00028 #include <QtCore/QByteArray>
00029 #include <QtCore/QCache>
00030 
00031 class KSharedDataCache::Private
00032 {
00033     public:
00034     KSharedDataCache::EvictionPolicy evictionPolicy;
00035     QCache<QString, QByteArray> cache;
00036 };
00037 
00038 KSharedDataCache::KSharedDataCache(const QString &cacheName,
00039                  unsigned defaultCacheSize,
00040                  unsigned expectedItemSize)
00041     : d(new Private)
00042 {
00043     d->cache.setMaxCost(defaultCacheSize);
00044 
00045     Q_UNUSED(cacheName);
00046     Q_UNUSED(expectedItemSize);
00047 }
00048 
00049 KSharedDataCache::~KSharedDataCache()
00050 {
00051     delete d;
00052 }
00053 
00054 KSharedDataCache::EvictionPolicy KSharedDataCache::evictionPolicy() const
00055 {
00056     return d->evictionPolicy;
00057 }
00058 
00059 void KSharedDataCache::setEvictionPolicy(KSharedDataCache::EvictionPolicy newPolicy)
00060 {
00061     d->evictionPolicy = newPolicy;
00062 }
00063 
00064 bool KSharedDataCache::insert(const QString &key, const QByteArray &data)
00065 {
00066     return d->cache.insert(key, new QByteArray(data));
00067 }
00068 
00069 bool KSharedDataCache::find(const QString &key, QByteArray *destination) const
00070 {
00071     QByteArray *value = d->cache.object(key);
00072 
00073     if (value) {
00074         destination = value;
00075         return true;
00076     }
00077     else {
00078         return false;
00079     }
00080 }
00081 
00082 void KSharedDataCache::clear()
00083 {
00084     d->cache.clear();
00085 }
00086 
00087 void KSharedDataCache::deleteCache(const QString &cacheName)
00088 {
00089     Q_UNUSED(cacheName);
00090 }
00091 
00092 bool KSharedDataCache::contains(const QString &key) const
00093 {
00094     return d->cache.contains(key);
00095 }
00096 
00097 unsigned KSharedDataCache::totalSize() const
00098 {
00099     return static_cast<unsigned>(d->cache.maxCost());
00100 }
00101 
00102 unsigned KSharedDataCache::freeSize() const
00103 {
00104     if (d->cache.totalCost() < d->cache.maxCost()) {
00105         return static_cast<unsigned>(d->cache.maxCost() - d->cache.totalCost());
00106     }
00107     else {
00108         return 0;
00109     }
00110 }

KDECore

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • 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
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal