-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcachemanager.h
More file actions
46 lines (32 loc) · 1.23 KB
/
cachemanager.h
File metadata and controls
46 lines (32 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef CACHEMANAGER_H
#define CACHEMANAGER_H
#include <string>
#include <unordered_map>
#include <list>
#include <QPixmap>
#include <QObject>
class CacheManager : public QObject {
Q_OBJECT // Add this macro for Qt's signal-slot mechanism
public:
explicit CacheManager(int cacheSize = 256); // Default size of 256
~CacheManager();
// Fetch an image from the cache
virtual QPixmap* getImageFromCache(const std::string& imageID);
// Check if the image exists in the cache
bool cacheContainsImage(const std::string& imageID) const;
// Store an image in the cache
virtual void storeImageInCache(const std::string& imageID, const QPixmap& data);
// Get current size of cache i.e. number of images cached
virtual int getCurrentCacheSize() const;
// Get maximum size of cache
int getMaxCacheSize() const;
void printCachedImages() const;
signals:
void cacheSizeChanged(int newSize);
private:
void evictImageFromCache();
int cacheSize; // Maximum size of the cache
std::unordered_map<std::string, std::list<std::pair<std::string, QPixmap>>::iterator> cacheMap;
std::list<std::pair<std::string, QPixmap>> cacheList; // Keeps track of the order for LRU
};
#endif // CACHEMANAGER_H