KCoreAddons

kshareddatacache.h
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 #ifndef KSHAREDDATACACHE_H
10 #define KSHAREDDATACACHE_H
11 
12 #include <kcoreaddons_export.h>
13 
14 class QString;
15 class QByteArray;
16 
49 class KCOREADDONS_EXPORT KSharedDataCache
50 {
51 public:
69  KSharedDataCache(const QString &cacheName,
70  unsigned defaultCacheSize,
71  unsigned expectedItemSize = 0);
73 
74  KSharedDataCache(const KSharedDataCache &) = delete;
75  KSharedDataCache &operator=(const KSharedDataCache &) = delete;
76 
77  enum EvictionPolicy {
78  // The default value for data in our shared memory will be 0, so it is
79  // important that whatever we want for the default value is also 0.
80  NoEvictionPreference = 0,
81  EvictLeastRecentlyUsed,
82  EvictLeastOftenUsed,
83  EvictOldest
84  };
85 
90  EvictionPolicy evictionPolicy() const;
91 
98  void setEvictionPolicy(EvictionPolicy newPolicy);
99 
107  bool insert(const QString &key, const QByteArray &data);
108 
125  bool find(const QString &key, QByteArray *destination) const;
126 
130  void clear();
131 
139  static void deleteCache(const QString &cacheName);
140 
149  bool contains(const QString &key) const;
150 
156  unsigned totalSize() const;
157 
164  unsigned freeSize() const;
165 
175  unsigned timestamp() const;
176 
208  void setTimestamp(unsigned newTimestamp);
209 
210 private:
211  class Private;
212  Private *d;
213 };
214 
215 #endif
A simple data cache which uses shared memory to quickly access data stored on disk.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Jul 12 2020 23:02:26 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.