ClickHouse/src/Common/FileCacheFactory.h

55 lines
1.3 KiB
C++
Raw Normal View History

2022-01-13 11:57:56 +00:00
#pragma once
#include <Common/FileCache_fwd.h>
2022-03-21 13:56:38 +00:00
#include <Common/FileCacheSettings.h>
2022-01-13 11:57:56 +00:00
#include <boost/noncopyable.hpp>
#include <unordered_map>
#include <mutex>
2022-06-23 15:46:27 +00:00
#include <list>
2022-01-13 11:57:56 +00:00
namespace DB
{
/**
* Creates a FileCache object for cache_base_path.
*/
class FileCacheFactory final : private boost::noncopyable
{
2022-06-21 13:42:36 +00:00
public:
struct FileCacheData
2022-03-21 13:56:38 +00:00
{
FileCachePtr cache;
FileCacheSettings settings;
2022-06-21 13:42:36 +00:00
FileCacheData(FileCachePtr cache_, const FileCacheSettings & settings_) : cache(cache_), settings(settings_) {}
2022-03-21 13:56:38 +00:00
};
2022-06-23 15:46:27 +00:00
using Caches = std::list<FileCacheData>;
using CacheByBasePath = std::unordered_map<std::string, Caches::iterator>;
using CacheByName = std::unordered_map<std::string, Caches::iterator>;
2022-01-13 11:57:56 +00:00
static FileCacheFactory & instance();
2022-06-21 13:42:36 +00:00
FileCachePtr getOrCreate(const std::string & cache_base_path, const FileCacheSettings & file_cache_settings, const std::string & name);
2022-01-13 11:57:56 +00:00
FileCachePtr get(const std::string & cache_base_path);
CacheByBasePath getAll();
2022-03-21 13:56:38 +00:00
const FileCacheSettings & getSettings(const std::string & cache_base_path);
2022-06-21 13:42:36 +00:00
FileCacheData getByName(const std::string & name);
2022-06-23 15:46:27 +00:00
CacheByName getAllByName();
2022-01-13 11:57:56 +00:00
2022-06-23 15:46:27 +00:00
private:
2022-01-13 11:57:56 +00:00
std::mutex mutex;
2022-06-23 15:46:27 +00:00
Caches caches;
2022-06-21 13:42:36 +00:00
CacheByBasePath caches_by_path;
CacheByName caches_by_name;
2022-01-13 11:57:56 +00:00
};
}