Skip to content

Instantly share code, notes, and snippets.

@kou-yeung
Last active November 20, 2017 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kou-yeung/9791877e17959a46348ba6eee48e6401 to your computer and use it in GitHub Desktop.
Save kou-yeung/9791877e17959a46348ba6eee48e6401 to your computer and use it in GitHub Desktop.
CardDatas getMasterCardDataByIds(const std::vector<uint32_t>& masterCardIds) const
{
// キャッシュされないID 一覧を作成
std::vector<uint32_t> needCache;
for (const auto& id : masterCardIds)
{
if (_cardDataCache.fetch(id) == nullptr) needCache.push_back(id);
}
// キャッシュされないものをストレージから取得する
if(needCache.size() > 0)
{
DatabaseManager::getInstance()->query(needCache, [this](CardDataPtr cardData)
{
_cardDataCache.store(cardData);
});
}
// キャッシュからカードデータ一覧を作成する
std::vector<CardDataPtr> result;
result.reserve(masterCardIds.size());
for (const auto& id : masterCardIds)
{
result.push_back(_cardDataCache.fetch(id));
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment