]> git.sur5r.net Git - minitube/blob - lib/http/src/localcache.h
90725e1e2696a894854dc7a4daae2f2da40c0a22
[minitube] / lib / 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     void clear();
23
24 private:
25     LocalCache(const QByteArray &name);
26     QString cachePath(const QByteArray &key) const;
27     bool isCached(const QString &path);
28     void 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     QMutex mutex;
39     uint insertCount;
40
41 #ifndef QT_NO_DEBUG_OUTPUT
42     uint hits;
43     uint misses;
44 #endif
45 };
46
47 #endif // LOCALCACHE_H