| 192 | static void write_u64(FILE * f, uint64_t v) { std::fwrite(&v, 8, 1, f); } |
| 193 | static void write_i64(FILE * f, int64_t v) { std::fwrite(&v, 8, 1, f); } |
| 194 | static void write_u16(FILE * f, uint16_t v) { std::fwrite(&v, 2, 1, f); } |
| 195 | |
| 196 | static bool read_u32(FILE * f, uint32_t & out) { return std::fread(&out, 4, 1, f) == 1; } |
| 197 | static bool read_u64(FILE * f, uint64_t & out) { return std::fread(&out, 8, 1, f) == 1; } |
| 198 | static bool read_i64(FILE * f, int64_t & out) { return std::fread(&out, 8, 1, f) == 1; } |
| 199 | static bool read_u16(FILE * f, uint16_t & out) { return std::fread(&out, 2, 1, f) == 1; } |
| 200 | |
| 201 | // ─── Construction ─────────────────────────────────────────────────────── |
| 202 | |
| 203 | DiskPrefixCache::DiskPrefixCache(const DiskCacheConfig & cfg, ModelBackend & backend) |
| 204 | : config_(cfg), backend_(backend) {} |
| 205 | |
| 206 | // ─── Initialization ───────────────────────────────────────────────────── |
| 207 | |
| 208 | bool DiskPrefixCache::init() { |
| 209 | if (disabled()) return true; |
| 210 | |
| 211 | if (!mkdir_p(config_.cache_dir)) { |
| 212 | std::fprintf(stderr, "[disk-cache] failed to create dir: %s\n", |
| 213 | config_.cache_dir.c_str()); |
| 214 | return false; |
no test coverage detected