mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 06:07:37 +02:00
Add documentation to cache
This commit is contained in:
@@ -29,6 +29,9 @@
|
|||||||
|
|
||||||
namespace TomahawkUtils {
|
namespace TomahawkUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal data structure. Don't use.
|
||||||
|
*/
|
||||||
struct CacheData {
|
struct CacheData {
|
||||||
CacheData(){}
|
CacheData(){}
|
||||||
CacheData( qint64 maxAg, QVariant dat )
|
CacheData( qint64 maxAg, QVariant dat )
|
||||||
@@ -36,10 +39,19 @@ struct CacheData {
|
|||||||
, data( dat )
|
, data( dat )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
qint64 maxAge;
|
qint64 maxAge; //!< milliseconds
|
||||||
QVariant data;
|
QVariant data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple generic cache for anyone to use.
|
||||||
|
*
|
||||||
|
* Data is segmented according to clients, which specify
|
||||||
|
* a client identifier.
|
||||||
|
*
|
||||||
|
* Structure is a basic key-value store with associated max lifetime in
|
||||||
|
* milliseconds.
|
||||||
|
*/
|
||||||
class DLLEXPORT Cache : public QObject
|
class DLLEXPORT Cache : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -48,7 +60,21 @@ public:
|
|||||||
static Cache* instance();
|
static Cache* instance();
|
||||||
virtual ~Cache();
|
virtual ~Cache();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store data in the cache.
|
||||||
|
* @param identifier your unique identifier, used to segment your data.
|
||||||
|
* @param maxAge lifetime of data in milliseconds (e.g, 3600000 = 1 hour)
|
||||||
|
* @param key the key to store the data
|
||||||
|
* @param value the data to store
|
||||||
|
*/
|
||||||
void putData( const QString &identifier, qint64 maxAge, const QString &key, const QVariant& value );
|
void putData( const QString &identifier, qint64 maxAge, const QString &key, const QVariant& value );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve data from the cache.
|
||||||
|
* @param identifier your unique identifier, used to segment your data.
|
||||||
|
* @param key the key to store the data
|
||||||
|
* @return the data, if found, if not found an invalid QVariant is returned.
|
||||||
|
*/
|
||||||
QVariant getData( const QString &identifier, const QString &key );
|
QVariant getData( const QString &identifier, const QString &key );
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
@@ -58,7 +84,16 @@ private:
|
|||||||
Cache();
|
Cache();
|
||||||
static Cache* s_instance;
|
static Cache* s_instance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a client to the manifest.
|
||||||
|
* Does not lock the mutex.
|
||||||
|
*/
|
||||||
void addClient( const QString &identifier );
|
void addClient( const QString &identifier );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a client to the manifest.
|
||||||
|
* Does not lock the mutex.
|
||||||
|
*/
|
||||||
void removeClient( const QString &identifier );
|
void removeClient( const QString &identifier );
|
||||||
|
|
||||||
QString m_cacheBaseDir;
|
QString m_cacheBaseDir;
|
||||||
|
Reference in New Issue
Block a user