userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
lru_set.hpp
Go to the documentation of this file.
1
#pragma once
2
5
6
#include <userver/cache/impl/lru.hpp>
7
8
USERVER_NAMESPACE_BEGIN
9
10
namespace
cache
{
11
15
template
<
16
typename
T,
17
typename
Hash = std::hash<impl::StringToStringView<T>>,
18
typename
Equal = std::equal_to<impl::StringToStringView<T>>>
19
class
LruSet final {
20
public
:
21
explicit
LruSet(
size_t
max_size,
const
Hash& hash = Hash(),
const
Equal& equal = Equal())
22
: impl_(max_size, hash, equal)
23
{}
24
25
LruSet(LruSet&& lru)
noexcept
=
default
;
26
LruSet(
const
LruSet& lru) =
delete
;
27
LruSet& operator=(LruSet&& lru)
noexcept
=
default
;
28
LruSet& operator=(
const
LruSet& lru) =
delete
;
29
32
bool
Put
(
const
T& key) {
return
impl_.Put(key, {}); }
33
35
void
Erase
(
const
T& key) {
return
impl_.Erase(key); }
36
38
bool
Has
(
const
T& key) {
return
impl_.Get(key); }
39
41
void
SetMaxSize
(
size_t
new_max_size) {
return
impl_.SetMaxSize(new_max_size); }
42
44
void
Invalidate
() {
return
impl_.Invalidate(); }
45
47
template
<
typename
Function>
48
void
VisitAll
(Function&& func)
const
{
49
impl_.VisitAll([&func](
const
auto
& key,
const
auto
&
/*value*/
)
mutable
{ func(key); });
50
}
51
52
size_t
GetSize()
const
{
return
impl_.GetSize(); }
53
57
const
T*
GetLeastUsed
() {
return
impl_.GetLeastUsedKey(); }
58
59
private
:
60
impl::LruBase<T, impl::EmptyPlaceholder, Hash, Equal> impl_;
61
};
62
63
}
// namespace cache
64
65
USERVER_NAMESPACE_END
userver
cache
lru_set.hpp
Generated on
for userver by
Doxygen
1.17.0