21#ifndef KICAD_DATABASE_CACHE_H
22#define KICAD_DATABASE_CACHE_H
27#include <unordered_map>
32template<
typename CacheValueType>
36 typedef std::pair<std::string, std::pair<time_t, CacheValueType>>
CACHE_ENTRY;
38 typedef std::unordered_map<std::string, typename std::list<CACHE_ENTRY>::iterator>
CACHE_TYPE;
49 void Put(
const std::string& aQuery,
const CacheValueType& aResult )
51 auto it =
m_cache.find( aQuery );
53 time_t time = std::chrono::system_clock::to_time_t( std::chrono::system_clock::now() );
56 std::make_pair( time, aResult ) ) );
75 bool Get(
const std::string& aQuery, CacheValueType& aResult )
77 auto it =
m_cache.find( aQuery );
82 time_t time = std::chrono::system_clock::to_time_t( std::chrono::system_clock::now() );
84 if( time - it->second->second.first >
m_maxAge )
93 aResult = it->second->second.second;
void Put(const std::string &aQuery, const CacheValueType &aResult)
std::pair< std::string, std::pair< time_t, CacheValueType > > CACHE_ENTRY
bool Get(const std::string &aQuery, CacheValueType &aResult)
std::list< CACHE_ENTRY > m_cacheMru
void SetMaxAge(time_t aMaxAge)
CACHE_TYPE::const_iterator CACHE_CITER
CacheValueType CACHE_VALUE
std::unordered_map< std::string, typename std::list< CACHE_ENTRY >::iterator > CACHE_TYPE
DATABASE_CACHE(size_t aMaxSize, time_t aMaxAge)
void SetMaxSize(size_t aMaxSize)