mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-08 04:21:51 +00:00
value cache: keep track of expired values in case of edition
This commit is contained in:
1 parent
6a45891ee7
commit
b2ff05407b
1 file changed
+10
@@ -165,6 +165,7 @@ private:
|
||||
CallbackQueue addValues(const std::vector<Sp<Value>>& new_values, const TypeStore& types, const time_point& now)
|
||||
{
|
||||
std::vector<Sp<Value>> nvals;
|
||||
std::vector<Sp<Value>> expired_vals;
|
||||
for (const auto& value : new_values) {
|
||||
auto v = values.find(value->id);
|
||||
if (v == values.end()) {
|
||||
@@ -175,9 +176,18 @@ private:
|
||||
// refreshed value
|
||||
v->second.created = now;
|
||||
v->second.expiration = now + types.getType(v->second.data->type).expiration;
|
||||
if (*v->second.data != *value) {
|
||||
expired_vals.emplace_back(v->second.data);
|
||||
v->second.data = value;
|
||||
nvals.emplace_back(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
CallbackQueue ret;
|
||||
if (callback and not expired_vals.empty())
|
||||
ret.emplace_back([cb = callback, expired_vals = std::move(expired_vals)]{
|
||||
cb(expired_vals, true);
|
||||
});
|
||||
if (callback and not nvals.empty())
|
||||
ret.emplace_back([cb = callback, nvals = std::move(nvals)] { cb(nvals, false); });
|
||||
return ret;
|
||||
|
||||
Reference in new issue
Block a user