Skip to content

Instantly share code, notes, and snippets.

@kou-yeung kou-yeung/main.cpp Secret
Last active Nov 20, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.