mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-16 11:04:01 +02:00
Add a QCache to cache recent hits in memory
This commit is contained in:
@@ -136,6 +136,7 @@ InfoSystemCache::getCachedInfoSlot( const Tomahawk::InfoSystem::InfoCriteriaHash
|
||||
|
||||
fileLocationHash.remove( criteriaHashVal );
|
||||
m_fileLocationCache[type] = fileLocationHash;
|
||||
m_dataCache.remove( criteriaHashVal );
|
||||
|
||||
emit notInCache( criteria, caller, type, input, customData );
|
||||
return;
|
||||
@@ -155,10 +156,16 @@ InfoSystemCache::getCachedInfoSlot( const Tomahawk::InfoSystem::InfoCriteriaHash
|
||||
m_fileLocationCache[type] = fileLocationHash;
|
||||
}
|
||||
|
||||
if ( !m_dataCache.contains( criteriaHashVal ) )
|
||||
{
|
||||
QSettings cachedSettings( fileLocationHash[criteriaHashVal], QSettings::IniFormat );
|
||||
QVariant output = cachedSettings.value( "data" );
|
||||
m_dataCache.insert( criteriaHashVal, new QVariant( output ) );
|
||||
|
||||
emit info( caller, type, input, output, customData );
|
||||
}
|
||||
else
|
||||
emit info( caller, type, input, QVariant( *(m_dataCache[criteriaHashVal]) ), customData );
|
||||
}
|
||||
|
||||
|
||||
@@ -185,6 +192,8 @@ InfoSystemCache::updateCacheSlot( const Tomahawk::InfoSystem::InfoCriteriaHash c
|
||||
QSettings cachedSettings( fileLocationHash[criteriaHashVal], QSettings::IniFormat );
|
||||
cachedSettings.setValue( "data", output );
|
||||
|
||||
m_dataCache.insert( criteriaHashVal, new QVariant( output ) );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -209,6 +218,7 @@ InfoSystemCache::updateCacheSlot( const Tomahawk::InfoSystem::InfoCriteriaHash c
|
||||
|
||||
fileLocationHash[criteriaHashVal] = settingsFilePath;
|
||||
m_fileLocationCache[type] = fileLocationHash;
|
||||
m_dataCache.insert( criteriaHashVal, new QVariant( output ) );
|
||||
}
|
||||
|
||||
|
||||
|
@@ -19,6 +19,7 @@
|
||||
#ifndef TOMAHAWK_INFOSYSTEMCACHE_H
|
||||
#define TOMAHAWK_INFOSYSTEMCACHE_H
|
||||
|
||||
#include <QCache>
|
||||
#include <QDateTime>
|
||||
#include <QObject>
|
||||
#include <QtDebug>
|
||||
@@ -58,6 +59,7 @@ private:
|
||||
QString m_cacheBaseDir;
|
||||
QHash< InfoType, QHash< QString, QString > > m_fileLocationCache;
|
||||
QTimer m_pruneTimer;
|
||||
QCache< QString, QVariant > m_dataCache;
|
||||
};
|
||||
|
||||
} //namespace InfoSystem
|
||||
|
Reference in New Issue
Block a user