diff --git a/src/libtomahawk/TomahawkSettings.cpp b/src/libtomahawk/TomahawkSettings.cpp index 28867067e..05f848c84 100644 --- a/src/libtomahawk/TomahawkSettings.cpp +++ b/src/libtomahawk/TomahawkSettings.cpp @@ -701,9 +701,20 @@ TomahawkSettings::setInfoSystemCacheVersion( uint version ) uint TomahawkSettings::infoSystemCacheVersion() const { - return value( "infosystemcacheversion", 3 ).toUInt(); + return value( "infosystemcacheversion", 0 ).toUInt(); } +void +TomahawkSettings::setGenericCacheVersion( uint version ) +{ + setValue( "genericcacheversion", version ); +} + +uint +TomahawkSettings::genericCacheVersion() const +{ + return value( "genericcacheversion", 0 ).toUInt(); +} QString TomahawkSettings::storageCacheLocation() const diff --git a/src/libtomahawk/TomahawkSettings.h b/src/libtomahawk/TomahawkSettings.h index d4e52d59b..491455557 100644 --- a/src/libtomahawk/TomahawkSettings.h +++ b/src/libtomahawk/TomahawkSettings.h @@ -60,6 +60,9 @@ public: uint infoSystemCacheVersion() const; void setInfoSystemCacheVersion( uint version ); + uint genericCacheVersion() const; + void setGenericCacheVersion( uint version ); + bool watchForChanges() const; void setWatchForChanges( bool watch ); diff --git a/src/libtomahawk/infosystem/InfoSystemCache.cpp b/src/libtomahawk/infosystem/InfoSystemCache.cpp index bf48317f6..26d64f6c0 100644 --- a/src/libtomahawk/infosystem/InfoSystemCache.cpp +++ b/src/libtomahawk/infosystem/InfoSystemCache.cpp @@ -35,6 +35,7 @@ namespace Tomahawk namespace InfoSystem { +const int InfoSystemCache::s_infosystemCacheVersion = 4; InfoSystemCache::InfoSystemCache( QObject* parent ) : QObject( parent ) @@ -42,6 +43,12 @@ InfoSystemCache::InfoSystemCache( QObject* parent ) { tDebug() << Q_FUNC_INFO; + if ( TomahawkSettings::instance()->infoSystemCacheVersion() < s_infosystemCacheVersion ) + { + TomahawkUtils::removeDirectory( m_cacheBaseDir ); + TomahawkSettings::instance()->setInfoSystemCacheVersion( s_infosystemCacheVersion ); + } + m_pruneTimer.setInterval( 300000 ); m_pruneTimer.setSingleShot( false ); connect( &m_pruneTimer, SIGNAL( timeout() ), SLOT( pruneTimerFired() ) ); diff --git a/src/libtomahawk/infosystem/InfoSystemCache.h b/src/libtomahawk/infosystem/InfoSystemCache.h index d21e32865..bc3689e99 100644 --- a/src/libtomahawk/infosystem/InfoSystemCache.h +++ b/src/libtomahawk/infosystem/InfoSystemCache.h @@ -54,6 +54,13 @@ private slots: void pruneTimerFired(); private: + /** + * Version number of the infosystem cache. + * If you change existing cached data, + * increase this number. + */ + static const int s_infosystemCacheVersion; + void notInCache( QObject *receiver, Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData ); const QString criteriaMd5( const Tomahawk::InfoSystem::InfoStringHash &criteria, Tomahawk::InfoSystem::InfoType type = Tomahawk::InfoSystem::InfoNoInfo ) const; diff --git a/src/libtomahawk/utils/TomahawkCache.cpp b/src/libtomahawk/utils/TomahawkCache.cpp index 5ff21da6e..58e79c8d4 100644 --- a/src/libtomahawk/utils/TomahawkCache.cpp +++ b/src/libtomahawk/utils/TomahawkCache.cpp @@ -29,6 +29,7 @@ using namespace TomahawkUtils; Cache*Cache::s_instance = 0; +const int Cache::s_cacheVersion = 1; Cache* Cache::instance() @@ -45,6 +46,12 @@ Cache::Cache() , m_cacheBaseDir( TomahawkSettings::instance()->storageCacheLocation() + "/GenericCache/" ) , m_cacheManifest( m_cacheBaseDir + "cachemanifest.ini", QSettings::IniFormat ) { + if ( TomahawkSettings::instance()->genericCacheVersion() < s_cacheVersion ) + { + TomahawkUtils::removeDirectory( m_cacheBaseDir ); + TomahawkSettings::instance()->setGenericCacheVersion( s_cacheVersion ); + } + m_pruneTimer.setInterval( 300000 ); m_pruneTimer.setSingleShot( false ); connect( &m_pruneTimer, SIGNAL( timeout() ), SLOT( pruneTimerFired() ) ); diff --git a/src/libtomahawk/utils/TomahawkCache.h b/src/libtomahawk/utils/TomahawkCache.h index 5cc3ece17..b7c3245f5 100644 --- a/src/libtomahawk/utils/TomahawkCache.h +++ b/src/libtomahawk/utils/TomahawkCache.h @@ -26,6 +26,7 @@ #include #include #include +#include namespace TomahawkUtils { @@ -86,6 +87,13 @@ private: Cache(); static Cache* s_instance; + /** + * Version number of the cache. + * If you change existing cached data, + * increase this number. + */ + static const int s_cacheVersion; + /** * Adds a client to the manifest. * Does not lock the mutex.