yiguolei commented on code in PR #21522:
URL: https://github.com/apache/doris/pull/21522#discussion_r1253272168


##########
be/src/runtime/memory/cache_policy.h:
##########
@@ -0,0 +1,133 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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 "olap/lru_cache.h"
+#include "util/stopwatch.hpp"
+#include "util/time.h"
+
+namespace doris {
+
+static constexpr int32_t CACHE_GC_MIN_FREE_SIZE = 67108864; // 64M
+
+template <typename T>
+class CachePolicy {
+public:
+    CachePolicy(const std::string& name) : _name(name) {}
+    virtual ~CachePolicy() = default;
+    virtual int64_t prune_stale() = 0;
+    virtual int64_t prune_all() = 0;
+
+    static void for_each_cahce_prune_stale();
+
+    static void for_each_cahce_prune_stale(int64_t& freed_mem,
+                                           std::unordered_map<std::string, 
int64_t>& freed_details,
+                                           std::unordered_map<std::string, 
uint64_t>& cost_details);
+
+    static void for_each_cahce_prune_all(int64_t& freed_mem,
+                                         std::unordered_map<std::string, 
int64_t>& freed_details,
+                                         std::unordered_map<std::string, 
uint64_t>& cost_details);
+
+protected:
+    static std::list<T*>::iterator register_cache(T* cache) {
+        std::lock_guard<std::mutex> l(_caches_policy_lock);
+        return _caches_policy.insert(_caches_policy.end(), cache);
+    }
+
+    static void unregister_cache(std::list<T*>::iterator& it) {
+        std::lock_guard<std::mutex> l(_caches_policy_lock);
+        if (it != _caches_policy.end()) {
+            _caches_policy.erase(it);
+            it = _caches_policy.end();
+        }
+    }
+
+    std::string _name;
+
+    static std::list<T*> _caches_policy;
+    static std::mutex _caches_policy_lock;
+};
+
+template <typename T>
+std::list<T*> CachePolicy<T>::_caches_policy;
+template <typename T>
+std::mutex CachePolicy<T>::_caches_policy_lock;
+
+struct CacheValuePolicy {

Review Comment:
   maybe it's name should be  CacheValueStats



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to