2022-01-13 11:57:56 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-01-30 11:35:28 +00:00
|
|
|
#include <Common/FileCache_fwd.h>
|
|
|
|
|
2022-01-13 11:57:56 +00:00
|
|
|
#include <boost/noncopyable.hpp>
|
|
|
|
#include <unordered_map>
|
2022-01-30 11:35:28 +00:00
|
|
|
#include <mutex>
|
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-03-21 11:30:25 +00:00
|
|
|
using CacheByBasePath = std::unordered_map<std::string, FileCachePtr>;
|
|
|
|
|
2022-01-13 11:57:56 +00:00
|
|
|
public:
|
|
|
|
static FileCacheFactory & instance();
|
|
|
|
|
2022-03-14 19:15:07 +00:00
|
|
|
FileCachePtr getOrCreate(const std::string & cache_base_path, const FileCacheSettings & file_cache_settings);
|
2022-01-13 11:57:56 +00:00
|
|
|
|
2022-03-21 11:30:25 +00:00
|
|
|
FileCachePtr get(const std::string & cache_base_path);
|
|
|
|
|
|
|
|
CacheByBasePath getAll();
|
|
|
|
|
2022-01-13 11:57:56 +00:00
|
|
|
private:
|
|
|
|
FileCachePtr getImpl(const std::string & cache_base_path, std::lock_guard<std::mutex> &);
|
|
|
|
|
|
|
|
std::mutex mutex;
|
2022-03-21 11:30:25 +00:00
|
|
|
CacheByBasePath caches;
|
2022-01-13 11:57:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|