SkyWay Linux SDK
読み取り中…
検索中…
一致する文字列を見つけられません
room_domain_cache_manager.hpp
1//
2// room_domain_cache_manager.hpp
3// skyway
4//
5// Created by iorar on 2025/07/18.
6// Copyright © 2025 NTT DOCOMO BUSINESS, Inc. All rights reserved.
7//
8
9#ifndef SKYWAY_ROOM_ROOM_DOMAIN_CACHE_MANAGER_HPP
10#define SKYWAY_ROOM_ROOM_DOMAIN_CACHE_MANAGER_HPP
11
12#include <map>
13#include <mutex>
14#include <unordered_map>
15
16#include "skyway/room/interface/room_domain_cache_manager.hpp"
17
18namespace skyway {
19namespace room {
20
22template <typename T>
23class RoomDomainCacheManager : public interface::RoomDomainCacheManager<T> {
24public:
25 ~RoomDomainCacheManager();
26 void CacheRoomDomainInstance(const std::string& id, std::shared_ptr<T> instance) override;
27 std::shared_ptr<T> FindCachedRoomDomainInstance(const std::string& id) override;
28 void RemoveCachedRoomDomainInstance(const std::string& id) override;
29
30private:
31 void ClearExpiredDeletedInstanceIds();
32 std::mutex mtx_;
33 std::unordered_map<std::string, std::shared_ptr<T>> cached_room_domain_instances_;
34
35 // To prevent memory leaks, we keep track of deleted instances.
36 // For efficient searching, two types of containers are used: search by ID and search by
37 // time.
38 std::unordered_map<std::string, std::chrono::steady_clock::time_point>
39 deleted_room_domain_instance_ids_by_id_;
40 std::multimap<std::chrono::steady_clock::time_point, std::string>
41 deleted_room_domain_instance_ids_by_time_;
42
43public:
44 friend class RoomDomainCacheManagerTest;
45};
47
48} // namespace room
49} // namespace skyway
50
51#endif /* SKYWAY_ROOM_ROOM_DOMAIN_CACHE_MANAGER_HPP */