Repository: duckdb/duckdb
File: src/include/duckdb/storage/caching_file_system_wrapper.hpp (C++)

Code before:
	CACHE_REMOTE_ONLY = 1,
};

//! CachingFileHandleWrapper wraps CachingFileHandle to conform to FileHandle API.
class CachingFileHandleWrapper : public FileHandle {
	friend class CachingFileSystemWrapper;

public:
	CachingFileHandleWrapper(CachingFileSystemWrapper &file_system, unique_ptr<CachingFileHandle> handle,
	                         FileOpenFlags flags);
	~CachingFileHandleWrapper() override;

	void Close() override;

private:
	unique_ptr<CachingFileHandle> caching_handle;
};

//! [CachingFileSystemWrapper] is an adapter class, which wraps [CachingFileSystem] to conform to FileSystem API.
//! Different from [CachingFileSystem], which owns cache content and returns a [BufferHandle] to achieve zero-copy on
//! read, the wrapper class always copies requested byted into the provided address.
//!
//! NOTICE: Currently only read and seek operations are supported, write operations are disabled.
class CachingFileSystemWrapper : public FileSystem {
public:
	CachingFileSystemWrapper(FileSystem &file_system, DatabaseInstance &db,
	                         CachingMode mode = CachingMode::CACHE_REMOTE_ONLY);
	~CachingFileSystemWrapper() override;

	static CachingFileSystemWrapper Get(ClientContext &context, CachingMode mode = CachingMode::CACHE_REMOTE_ONLY);

	std::string GetName() const override;

	unique_ptr<FileHandle> OpenFile(const string &path, FileOpenFlags flags,
	                                optional_ptr<FileOpener> opener = nullptr) override;
	unique_ptr<FileHandle> OpenFile(const OpenFileInfo &path, FileOpenFlags flags,
	                                optional_ptr<FileOpener> opener = nullptr);

	void Read(FileHandle &handle, void *buffer, int64_t nr_bytes, idx_t location) override;
	void Write(FileHandle &handle, void *buffer, int64_t nr_bytes, idx_t location) override;
	int64_t Read(FileHandle &handle, void *buffer, int64_t nr_bytes) override;
	int64_t Write(FileHandle &handle, void *buffer, int64_t nr_bytes) override;
	bool Trim(FileHandle &handle, idx_t offset_bytes, idx_t length_bytes) override;

	int64_t GetFileSize(FileHandle &handle) override;
	timestamp_t GetLastModifiedTime(FileHandle &handle) override;
	string GetVersionTag(FileHandle &handle) override;
	FileType GetFileType(FileHandle &handle) override;
	FileMetadata Stats(FileHandle &handle) override;
	void Truncate(FileHandle &handle, int64_t new_size) override;
	void FileSync(FileHandle &handle) override;

Review comment (suggestion):
All `DUCKDB_API` annotation is removed -- I think it should be the same as other wrapper filesystems like `VirtualFileSystem`.

Code after:

public:
	DUCKDB_API CachingFileHandleWrapper(shared_ptr<CachingFileSystemWrapper> file_system,
	                                    unique_ptr<CachingFileHandle> handle, FileOpenFlags flags);

	DUCKDB_API ~CachingFileHandleWrapper() override;

	DUCKDB_API void Close() override;

private:
	// CachingFileSystem is not kept within VFS as other filesystems, so sometimes it's necessary to pin it inside of
	// file handle and ensure it's valid.
	shared_ptr<CachingFileSystemWrapper> caching_file_system;

	unique_ptr<CachingFileHandle> caching_handle;
};

//! [CachingFileSystemWrapper] is an adapter class, which wraps [CachingFileSystem] to conform to FileSystem API.
//! Different from [CachingFileSystem], which owns cache content and returns a [BufferHandle] to achieve zero-copy on
//! read, the wrapper class always copies requested byted into the provided address.
//!
//! NOTICE: Currently only read and seek operations are supported, write operations are disabled.
class CachingFileSystemWrapper : public FileSystem, public enable_shared_from_this<CachingFileSystemWrapper> {
public:
	DUCKDB_API CachingFileSystemWrapper(FileSystem &file_system, DatabaseInstance &db,
	                                    CachingMode mode = CachingMode::CACHE_REMOTE_ONLY);
	DUCKDB_API CachingFileSystemWrapper(FileSystem &file_system, optional_ptr<FileOpener> file_opener,
	                                    CachingMode mode = CachingMode::CACHE_REMOTE_ONLY);
	DUCKDB_API ~CachingFileSystemWrapper() override;

	DUCKDB_API std::string GetName() const override;

	DUCKDB_API unique_ptr<FileHandle> OpenFile(const string &path, FileOpenFlags flags,
	                                           optional_ptr<FileOpener> opener = nullptr) override;
	DUCKDB_API unique_ptr<FileHandle> OpenFile(const OpenFileInfo &path, FileOpenFlags flags,
	                                           optional_ptr<FileOpener> opener = nullptr);

	DUCKDB_API void Read(FileHandle &handle, void *buffer, int64_t nr_bytes, idx_t location) override;
	DUCKDB_API void Write(FileHandle &handle, void *buffer, int64_t nr_bytes, idx_t location) override;
	DUCKDB_API int64_t Read(FileHandle &handle, void *buffer, int64_t nr_bytes) override;
	DUCKDB_API int64_t Write(FileHandle &handle, void *buffer, int64_t nr_bytes) override;
	DUCKDB_API bool Trim(FileHandle &handle, idx_t offset_bytes, idx_t length_bytes) override;

	DUCKDB_API int64_t GetFileSize(FileHandle &handle) override;
	DUCKDB_API timestamp_t GetLastModifiedTime(FileHandle &handle) override;
	DUCKDB_API string GetVersionTag(FileHandle &handle) override;
	DUCKDB_API FileType GetFileType(FileHandle &handle) override;
	DUCKDB_API FileMetadata Stats(FileHandle &handle) override;
	DUCKDB_API void Truncate(FileHandle &handle, int64_t new_size) override;
	DUCKDB_API void FileSync(FileHandle &handle) override;