| 179 | } |
| 180 | |
| 181 | std::unique_ptr<WriteBufferFromFileBase> |
| 182 | DiskCacheWrapper::writeFile(const String & path, const WriteSettings& settings) |
| 183 | { |
| 184 | if (!cache_file_predicate(path)) |
| 185 | return DiskDecorator::writeFile(path, settings); |
| 186 | |
| 187 | LOG_DEBUG(log, "Write file {} to cache", backQuote(path)); |
| 188 | |
| 189 | auto dir_path = directoryPath(path); |
| 190 | if (!cache_disk->exists(dir_path)) |
| 191 | cache_disk->createDirectories(dir_path); |
| 192 | |
| 193 | return std::make_unique<CompletionAwareWriteBuffer>( |
| 194 | cache_disk->writeFile(path, settings), |
| 195 | [this, path, settings]() |
| 196 | { |
| 197 | /// Copy file from cache to actual disk when cached buffer is finalized. |
| 198 | auto src_buffer = cache_disk->readFile(path, ReadSettings().initializeReadSettings(settings.buffer_size)); |
| 199 | auto dst_buffer = DiskDecorator::writeFile(path, settings); |
| 200 | copyData(*src_buffer, *dst_buffer); |
| 201 | dst_buffer->finalize(); |
| 202 | }); |
| 203 | } |
| 204 | |
| 205 | void DiskCacheWrapper::clearDirectory(const String & path) |
| 206 | { |
no test coverage detected