]> git.sur5r.net Git - minitube/blob - lib/http/src/localcache.h
New upstream version 3.6.1
[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     QByteArray possiblyStaleValue(const QByteArray &key);
22     void insert(const QByteArray &key, const QByteArray &value);
23     void clear();
24
25 private:
26     LocalCache(const QByteArray &name);
27     QString cachePath(const QByteArray &key) const;
28     bool isCached(const QString &path);
29     void expire();
30 #ifndef QT_NO_DEBUG_OUTPUT
31     void debugStats();
32 #endif
33
34     QByteArray name;
35     QString directory;
36     uint maxSeconds;
37     qint64 maxSize;
38     qint64 size;
39     QMutex mutex;
40     uint insertCount;
41
42 #ifndef QT_NO_DEBUG_OUTPUT
43     uint hits;
44     uint misses;
45 #endif
46 };
47
48 #endif // LOCALCACHE_H