blob: 7a9a3ef4c723fb1d0c90813a56c41192fb270b94 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
#ifndef ENTCACHE_H
#define ENTCACHE_H
#include "entryResolver.h"
#include <c++11Helpers.h>
#include <shared_mutex>
template<class entry_t> class EntCache : public EntryResolver<entry_t> {
public:
EntCache();
~EntCache() noexcept override;
SPECIAL_MEMBERS_DEFAULT_MOVE_NO_COPY(EntCache);
using id_t = decltype(entry_t::id);
using name_t = decltype(entry_t::name);
using entry_ptr = std::shared_ptr<entry_t>;
[[nodiscard]] entry_ptr inline getEntry(const id_t & i) const noexcept override
{
return getEntryInternal<id_t>(i);
}
[[nodiscard]] entry_ptr inline getEntry(const name_t & n) const noexcept override
{
return getEntryInternal<name_t>(n);
};
protected:
void fillCache() const noexcept;
template<class key_t>[[nodiscard]] entry_ptr getEntryInternal(const key_t &) const noexcept;
template<class key_t>[[nodiscard]] entry_ptr getEntryNoFill(const key_t &) const noexcept;
class Ids;
std::unique_ptr<Ids> idcache;
mutable std::shared_mutex lock;
mutable time_t fillTime {0};
};
#endif
|