-
Notifications
You must be signed in to change notification settings - Fork 46
/
NearCacheSupport.h
74 lines (66 loc) · 2.61 KB
/
NearCacheSupport.h
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* Copyright (c) 2008-2023, Hazelcast, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <hazelcast/client/hazelcast.h>
class NearCacheSupport
{
public:
static constexpr int CACHE_INVALIDATION_MESSAGE_BATCH_FREQUENCY_SECONDS =
10; // seconds
static void print_near_cache_stats(
std::shared_ptr<hazelcast::client::imap>& map,
const char* message)
{
auto stats = map->get_local_map_stats().get_near_cache_stats();
printf("%s (%ld entries, %ld hits, %ld misses, %ld evictions, %ld "
"expirations)\n",
message,
(long)stats->get_owned_entry_count(),
(long)stats->get_hits(),
(long)stats->get_misses(),
(long)stats->get_evictions(),
(long)stats->get_expirations());
}
static void print_near_cache_stats(
std::shared_ptr<hazelcast::client::imap>& map)
{
auto stats = map->get_local_map_stats().get_near_cache_stats();
printf("The Near Cache contains %ld entries.\n",
(long)stats->get_owned_entry_count());
printf("The first article instance was retrieved from the remote "
"instance (Near Cache misses: %ld).\n",
(long)stats->get_misses());
printf("The second and third article instance were retrieved from the "
"local Near Cache (Near Cache hits: %ld).\n",
(long)stats->get_hits());
}
static void wait_for_invalidation_events()
{
std::this_thread::sleep_for(std::chrono::seconds(
2 * CACHE_INVALIDATION_MESSAGE_BATCH_FREQUENCY_SECONDS));
}
static void wait_for_near_cache_eviction_count(
std::shared_ptr<hazelcast::client::imap>& map,
int64_t expected_eviction_count)
{
int64_t evictionCount;
do {
auto stats = map->get_local_map_stats().get_near_cache_stats();
evictionCount = stats->get_evictions();
std::this_thread::sleep_for(std::chrono::milliseconds(500));
} while (evictionCount > expected_eviction_count);
}
};