Branch data Line data Source code
1 : : // Copyright 2026 HPActor Contributors
2 : : //
3 : : // Licensed under the Apache License, Version 2.0 (the "License");
4 : : // you may not use this file except in compliance with the License.
5 : : // You may obtain a copy of the License at
6 : : //
7 : : // http://www.apache.org/licenses/LICENSE-2.0
8 : : //
9 : : // Unless required by applicable law or agreed to in writing, software
10 : : // distributed under the License is distributed on an "AS IS" BASIS,
11 : : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : : // See the License for the specific language governing permissions and
13 : : // limitations under the License.
14 : :
15 : : #pragma once
16 : :
17 : : #include <hpactor/types/types.hpp>
18 : : #include <hpactor/ref/actor_address.hpp>
19 : :
20 : : #include <chrono>
21 : : #include <optional>
22 : : #include <shared_mutex>
23 : : #include <unordered_map>
24 : :
25 : : namespace hpactor::net {
26 : :
27 : : class ActorLocationCache {
28 : : public:
29 : : std::optional<EndPoint> get(ActorId id) const;
30 : : void put(ActorId id, EndPoint ep,
31 : 5 : std::chrono::seconds ttl = std::chrono::seconds(30));
32 : : void evict(ActorId id);
33 : : void evict_node(EndPoint ep);
34 : : void purge_expired();
35 : :
36 : : private:
37 : : struct Entry {
38 : : EndPoint endpoint;
39 : : std::chrono::steady_clock::time_point expires_at;
40 : : };
41 : : std::unordered_map<ActorId, Entry> cache_;
42 : : mutable std::shared_mutex mutex_;
43 : : };
44 : :
45 : : } // namespace hpactor::net
|