Fix caching strategy

Fixes https://gitlab.com/kicad/code/kicad/-/issues/7960
This commit is contained in:
Jon Evans 2021-03-19 12:12:41 -04:00
parent f9bfa831e5
commit 7231f1dc68
2 changed files with 18 additions and 1 deletions

View File

@ -164,7 +164,14 @@ void SETTINGS_MANAGER::FlushAndRelease( JSON_SETTINGS* aSettings, bool aSave )
if( aSave )
( *it )->SaveToFile( GetPathForSettingsFile( it->get() ) );
size_t typeHash = typeid( *it->get() ).hash_code();
if( m_app_settings_cache.count( typeHash ) )
m_app_settings_cache.erase( typeHash );
m_settings.erase( it );
}
}

View File

@ -21,6 +21,7 @@
#ifndef _SETTINGS_MANAGER_H
#define _SETTINGS_MANAGER_H
#include <typeinfo>
#include <common.h> // for wxString hash
#include <settings/color_settings.h>
@ -85,7 +86,11 @@ public:
template<typename AppSettings>
AppSettings* GetAppSettings( bool aLoadNow = true )
{
static AppSettings* ret = nullptr;
AppSettings* ret = nullptr;
size_t typeHash = typeid( AppSettings ).hash_code();
if( m_app_settings_cache.count( typeHash ) )
ret = dynamic_cast<AppSettings*>( m_app_settings_cache.at( typeHash ) );
if( ret )
return ret;
@ -113,6 +118,8 @@ public:
}
m_app_settings_cache[typeHash] = ret;
return ret;
}
@ -395,6 +402,9 @@ private:
std::unordered_map<wxString, COLOR_SETTINGS*> m_color_settings;
/// Cache for app settings
std::unordered_map<size_t, JSON_SETTINGS*> m_app_settings_cache;
// Convenience shortcut
COMMON_SETTINGS* m_common_settings;