@@ -30,88 +30,6 @@ namespace cloud {
3030namespace storage_internal {
3131GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
3232
33- struct BucketCacheEntry {
34- std::string id;
35- std::string location;
36- };
37-
38- class BucketMetadataCache {
39- public:
40- explicit BucketMetadataCache (std::size_t max_size = 10000 )
41- : max_size_(max_size) {}
42-
43- absl::optional<BucketCacheEntry> Get (std::string const & bucket_name) {
44- std::lock_guard<std::mutex> lock (mu_);
45- auto it = map_.find (bucket_name);
46- if (it == map_.end ()) return absl::nullopt ;
47-
48- list_.erase (it->second .second );
49- list_.push_front (bucket_name);
50- it->second .second = list_.begin ();
51- return it->second .first ;
52- }
53-
54- void Put (std::string const & bucket_name, BucketCacheEntry entry) {
55- std::lock_guard<std::mutex> lock (mu_);
56- auto it = map_.find (bucket_name);
57- if (it != map_.end ()) {
58- it->second .first = entry;
59- list_.erase (it->second .second );
60- list_.push_front (bucket_name);
61- it->second .second = list_.begin ();
62- return ;
63- }
64-
65- if (map_.size () >= max_size_) {
66- auto oldest = list_.back ();
67- list_.pop_back ();
68- map_.erase (oldest);
69- }
70-
71- list_.push_front (bucket_name);
72- map_[bucket_name] = {std::move (entry), list_.begin ()};
73- }
74-
75- void Invalidate (std::string const & bucket_name) {
76- std::lock_guard<std::mutex> lock (mu_);
77- auto it = map_.find (bucket_name);
78- if (it != map_.end ()) {
79- list_.erase (it->second .second );
80- map_.erase (it);
81- }
82- }
83-
84- void Clear () {
85- std::lock_guard<std::mutex> lock (mu_);
86- map_.clear ();
87- list_.clear ();
88- in_flight_fetch_.clear ();
89- }
90-
91- bool StartFetch (std::string const & bucket_name) {
92- std::lock_guard<std::mutex> lock (mu_);
93- if (in_flight_fetch_.find (bucket_name) != in_flight_fetch_.end ()) {
94- return false ;
95- }
96- in_flight_fetch_.insert (bucket_name);
97- return true ;
98- }
99-
100- void EndFetch (std::string const & bucket_name) {
101- std::lock_guard<std::mutex> lock (mu_);
102- in_flight_fetch_.erase (bucket_name);
103- }
104-
105- private:
106- std::size_t max_size_;
107- std::mutex mu_;
108- std::list<std::string> list_;
109- std::unordered_map<std::string, std::pair<BucketCacheEntry,
110- std::list<std::string>::iterator>>
111- map_;
112- std::unordered_set<std::string> in_flight_fetch_;
113- };
114-
11533class TracingConnection : public storage ::internal::StorageConnection {
11634 public:
11735 using AsyncRunner = std::function<void (std::function<void ()>)>;
0 commit comments