]> git.sur5r.net Git - minitube/blob - src/http/src/localcache.h
Update watch file to use releases instead of tags
[minitube] / src / http / src / localcache.h
1 #ifndef LOCALCACHE_H
2 #define LOCALCACHE_H
3
4 #include <QtCore>
5
6 /**
7  * @brief Not thread-safe
8  */
9 class LocalCache {
10 public:
11     static LocalCache *instance(const char *name);
12     ~LocalCache();
13     static QByteArray hash(const QByteArray &s);
14
15     const QByteArray &getName() const { return name; }
16
17     void setMaxSeconds(uint value) { maxSeconds = value; }
18     void setMaxSize(uint value) { maxSize = value; }
19
20     QByteArray value(const QByteArray &key);
21     void insert(const QByteArray &key, const QByteArray &value);
22     bool clear();
23
24 private:
25     LocalCache(const QByteArray &name);
26     QString cachePath(const QByteArray &key) const;
27     bool isCached(const QString &path);
28     qint64 expire();
29 #ifndef QT_NO_DEBUG_OUTPUT
30     void debugStats();
31 #endif
32
33     QByteArray name;
34     QString directory;
35     uint maxSeconds;
36     qint64 maxSize;
37     qint64 size;
38     bool expiring;
39     uint insertCount;
40     struct QueueItem {
41         QByteArray key;
42         QByteArray value;
43     };
44     QVector<QueueItem> insertQueue;
45
46 #ifndef QT_NO_DEBUG_OUTPUT
47     uint hits;
48     uint misses;
49 #endif
50 };
51
52 #endif // LOCALCACHE_H