14#include "kshareddatacache.h"
23 KSharedDataCache::EvictionPolicy evictionPolicy;
24 QCache<QString, QByteArray> cache;
30 d->cache.setMaxCost(defaultCacheSize);
33 Q_UNUSED(expectedItemSize);
36KSharedDataCache::~KSharedDataCache()
43 return d->evictionPolicy;
48 d->evictionPolicy = newPolicy;
53 return d->cache.insert(key,
new QByteArray(data));
58 QByteArray *value = d->cache.object(key);
62 *destination = *value;
82 return d->cache.contains(key);
87 return static_cast<unsigned>(d->cache.maxCost());
92 if (d->cache.totalCost() < d->cache.maxCost()) {
93 return static_cast<unsigned>(d->cache.maxCost() - d->cache.totalCost());
106 Q_UNUSED(newTimestamp);
A simple data cache which uses shared memory to quickly access data stored on disk.
unsigned freeSize() const
Returns the amount of free space in the cache, in bytes.
static void deleteCache(const QString &cacheName)
Removes the underlying file from the cache.
void clear()
Removes all entries from the cache.
unsigned totalSize() const
Returns the usable cache size in bytes.
void setEvictionPolicy(EvictionPolicy newPolicy)
Sets the entry removal policy for the shared cache to newPolicy.
KSharedDataCache(const QString &cacheName, unsigned defaultCacheSize, unsigned expectedItemSize=0)
Attaches to a shared cache, creating it if necessary.
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 timestamp() const
bool contains(const QString &key) const
Returns true if the cache currently contains the image for the given filename.
EvictionPolicy evictionPolicy() const
void setTimestamp(unsigned newTimestamp)
Sets the shared timestamp of the cache.
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...