HTTP Libraries: Improved cache performance

This commit is contained in:
Andre Iwers 2024-01-18 02:33:16 +00:00 committed by Jon Evans
parent 97cb15dd47
commit 4d1a016429
4 changed files with 16 additions and 11 deletions

View File

@ -178,12 +178,16 @@ bool HTTP_LIB_CONNECTION::SelectOne( const std::string& aPartID, HTTP_LIB_PART&
return false;
}
// if the same part is selected again and cache has not expired use cached part
// instead to minimise http requests.
if( m_cached_part.id == aPartID && ( std::difftime( std::time( nullptr ), m_cached_part.lastCached ) < m_timeout ) )
// Check if there is already a part in our cache, if not fetch it
if( m_cachedParts.find( aPartID ) != m_cachedParts.end() )
{
aFetchedPart = m_cached_part;
return true;
// check if it's outdated, if so re-fetch
if( std::difftime( std::time( nullptr ), m_cachedParts[aPartID].lastCached ) < m_timeout )
{
aFetchedPart = m_cachedParts[aPartID];
return true;
}
}
std::string res = "";
@ -290,7 +294,7 @@ bool HTTP_LIB_CONNECTION::SelectOne( const std::string& aPartID, HTTP_LIB_PART&
return false;
}
m_cached_part = aFetchedPart;
m_cachedParts[aFetchedPart.id] = aFetchedPart;
return true;
}

View File

@ -70,7 +70,7 @@ void SCH_IO_HTTP_LIB::EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
&& aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
// clear buffer
m_cachedParts.clear();
m_cachedCategoryParts.clear();
for(const HTTP_LIB_CATEGORY& category : m_conn->getCategories() )
{
@ -89,7 +89,7 @@ void SCH_IO_HTTP_LIB::EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
}
// cache information for later use in LoadSymbol()
m_cachedParts.emplace( category.id, found_parts );
m_cachedCategoryParts.emplace( category.id, found_parts );
for( const HTTP_LIB_PART& part : found_parts )
{
@ -147,7 +147,7 @@ LIB_SYMBOL* SCH_IO_HTTP_LIB::LoadSymbol( const wxString& aLibraryPath,
}
// get the matching query ID
for( const HTTP_LIB_PART& part : m_cachedParts[foundCategory->id] )
for( const HTTP_LIB_PART& part : m_cachedCategoryParts[foundCategory->id] )
{
if( part.id == std::get<0>( relations ) )
{

View File

@ -100,7 +100,7 @@ private:
SYMBOL_LIB_TABLE* m_libTable;
std::map<std::string, std::vector<HTTP_LIB_PART>> m_cachedParts;
std::map<std::string, std::vector<HTTP_LIB_PART>> m_cachedCategoryParts;
/// Generally will be null if no valid connection is established
std::unique_ptr<HTTP_LIB_CONNECTION> m_conn;

View File

@ -94,7 +94,8 @@ private:
HTTP_LIB_SOURCE_TYPE m_sourceType;
HTTP_LIB_PART m_cached_part;
// part.id part
std::map<std::string, HTTP_LIB_PART> m_cachedParts;
// part.name part.id category.id
std::map<std::string, std::tuple<std::string, std::string>> m_cache;