forked from blue/lmdbal
methods to check elements without deserialization
This commit is contained in:
parent
08daad48ad
commit
6ff22c9377
4 changed files with 59 additions and 1 deletions
32
cache.hpp
32
cache.hpp
|
@ -137,11 +137,41 @@ V DataBase::Cache<K, V>::getRecord(const K& key) const {
|
|||
handleMode();
|
||||
return value;
|
||||
} catch (const NotFound& error) {
|
||||
abscent->insert(key);
|
||||
if (*mode != Mode::full) {
|
||||
abscent->insert(key);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
template<class K, class V>
|
||||
bool DataBase::Cache<K, V>::checkRecord(const K& key) const {
|
||||
if (!DataBase::Table<K, V>::db->opened) {
|
||||
throw Closed("checkRecord", DataBase::Table<K, V>::db->name, DataBase::Table<K, V>::name);
|
||||
}
|
||||
|
||||
typename std::map<K, V>::const_iterator itr = cache->find(key);
|
||||
if (itr != cache->end()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (*mode == Mode::full || abscent->count(key) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
V value = Table<K, V>::getRecord(key);
|
||||
cache->insert(std::make_pair(key, value));
|
||||
handleMode();
|
||||
return true;
|
||||
} catch (const NotFound& error) {
|
||||
if (*mode != Mode::full) {
|
||||
abscent->insert(key);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template<class K, class V>
|
||||
std::map<K, V> DataBase::Cache<K, V>::readAll() const {
|
||||
if (!DataBase::Table<K, V>::db->opened) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue