1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-25 02:09:48 +01:00

Add a QCache to cache recent hits in memory

This commit is contained in:
Jeff Mitchell 2011-04-22 13:02:35 -04:00
parent e3aa497b62
commit 7239d3fdfd
2 changed files with 16 additions and 4 deletions

View File

@ -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;
}
QSettings cachedSettings( fileLocationHash[criteriaHashVal], QSettings::IniFormat );
QVariant output = cachedSettings.value( "data" );
emit info( caller, type, input, output, customData );
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 );
}
@ -184,6 +191,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 ) );
}

View File

@ -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