| 24 | } |
| 25 | |
| 26 | std::shared_ptr<StatsCollection> StatisticsCache::get(const UUID & table, const std::optional<String> & column) |
| 27 | { |
| 28 | auto now = chrono::steady_clock::now(); |
| 29 | std::shared_lock lck(mutex); |
| 30 | if (auto iter = impl.find(table); iter != impl.end()) |
| 31 | { |
| 32 | auto key = column.value_or(""); |
| 33 | if (auto iter2 = iter->second.find(key); iter2 != iter->second.end()) |
| 34 | { |
| 35 | auto entry = iter2->second; |
| 36 | if (now > entry.expire_time_point) |
| 37 | { |
| 38 | // we don't delete expired cache entry here since we are holding a shared mutex |
| 39 | // expired entry will be cleaned only when invalidate and update |
| 40 | // since normally a missed cache will usually be followed with a update request |
| 41 | // this design won't have any performance issues comparing to Poco::ExpiredCache |
| 42 | return nullptr; |
| 43 | } |
| 44 | return entry.data; |
| 45 | } |
| 46 | } |
| 47 | return nullptr; |
| 48 | } |
| 49 | |
| 50 | void StatisticsCache::update(const UUID & table, const std::optional<String> column, std::shared_ptr<StatsCollection> data) |
| 51 | { |