// Squawk messenger. // Copyright (C) 2019 Yury Gubich // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . #include "cache.h" #include template class Core::Cache; template Core::Cache::Cache(const QString& name): storage(name), cache(new std::map ()) {} template Core::Cache::~Cache() { close(); delete cache; } template void Core::Cache::open() { storage.open();} template void Core::Cache::close() { storage.close();} template void Core::Cache::addRecord(const QString& key, const T& value) { storage.addRecord(key, value); cache->insert(std::make_pair(key, value)); } template T Core::Cache::getRecord(const QString& key) const { typename std::map::const_iterator itr = cache->find(key); if (itr == cache->end()) { T value = storage.getRecord(key); itr = cache->insert(std::make_pair(key, value)).first; } return itr->second; } template void Core::Cache::changeRecord(const QString& key, const T& value) { storage.changeRecord(key, value); cache->at(key) = value; } template void Core::Cache::removeRecord(const QString& key) { storage.removeRecord(key); cache->erase(key); }