implemented the first version of statement_cache
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
#ifndef STATEMENT_CACHE_HPP
|
||||
#define STATEMENT_CACHE_HPP
|
||||
|
||||
#include "matador/sql/executor.hpp"
|
||||
|
||||
#include "matador/sql/interface/statement_proxy.hpp"
|
||||
|
||||
#include <list>
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
class connection_pool;
|
||||
|
||||
class statement_cache final {
|
||||
public:
|
||||
explicit statement_cache(connection_pool &pool, size_t max_size = 50);
|
||||
|
||||
[[nodiscard]] utils::result<statement, utils::error> acquire(const query_context &ctx);
|
||||
|
||||
[[nodiscard]] size_t size() const;
|
||||
[[nodiscard]] size_t capacity() const;
|
||||
[[nodiscard]] bool empty() const;
|
||||
|
||||
private:
|
||||
using list_iterator = std::list<size_t>::iterator;
|
||||
|
||||
size_t max_size_{};
|
||||
std::list<size_t> usage_list_; // LRU: front = most recent, back = least recent
|
||||
std::unordered_map<size_t, std::pair<statement, list_iterator>> cache_map_;
|
||||
std::mutex mutex_;
|
||||
|
||||
connection_pool &pool_;
|
||||
const sql::dialect &dialect_;
|
||||
};
|
||||
}
|
||||
#endif //STATEMENT_CACHE_HPP
|
||||
Reference in New Issue
Block a user