Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
scan_cache.hpp
Go to the documentation of this file.
1#pragma once
2
3// Persistent plugin scan cache.
4//
5// Stores PluginInfo results keyed by (path, mtime, size). On the second scan
6// of an unchanged plugin file, the cache returns the stored PluginInfo
7// without re-inspecting the plugin binary. Entries auto-invalidate when the
8// underlying file changes.
9//
10// Format: JSON file. Schema versioned so future changes can force a flush.
11// Usage:
12// HostScanCache cache;
13// cache.load_from("/path/to/cache.json"); // best-effort; silent on miss
14// if (auto info = cache.get("/path/to/plugin.vst3")) { ... }
15// else { PluginInfo fresh = ...; cache.put("/path/to/plugin.vst3", fresh); }
16// cache.save_to("/path/to/cache.json");
17
18#include <pulp/host/scanner.hpp>
19
20#include <optional>
21#include <string>
22#include <unordered_map>
23
24namespace pulp::host {
25
27 int64_t mtime = 0; // seconds since epoch; 0 means "unknown" (never matches)
28 int64_t size = 0; // bytes
30};
31
33public:
35 static constexpr int kSchemaVersion = 1;
36
40 std::optional<PluginInfo> get(const std::string& path) const;
41
44 void put(const std::string& path, const PluginInfo& info);
45
47 void erase(const std::string& path);
48
50 std::size_t size() const { return entries_.size(); }
51
53 void clear() { entries_.clear(); }
54
57 bool save_to(const std::string& file_path) const;
58
64 bool load_from(const std::string& file_path);
65
66 // ── Serialization helpers exposed for unit tests ──────────────────────
67 std::string to_json() const;
68 bool from_json(const std::string& json);
69
70 // ── Raw access for tests / diagnostics ────────────────────────────────
71 const std::unordered_map<std::string, ScanCacheEntry>& entries() const {
72 return entries_;
73 }
74
75private:
76 std::unordered_map<std::string, ScanCacheEntry> entries_;
77};
78
79} // namespace pulp::host
Definition scan_cache.hpp:32
void clear()
Drop every entry.
Definition scan_cache.hpp:53
std::size_t size() const
Total number of entries currently in memory.
Definition scan_cache.hpp:50
std::string to_json() const
static constexpr int kSchemaVersion
Schema version; entries loaded with a different version are discarded.
Definition scan_cache.hpp:35
bool load_from(const std::string &file_path)
Load a JSON file produced by save_to().
void put(const std::string &path, const PluginInfo &info)
Overwrite (or insert) an entry for path.
const std::unordered_map< std::string, ScanCacheEntry > & entries() const
Definition scan_cache.hpp:71
void erase(const std::string &path)
Remove the entry for path (noop if absent).
bool from_json(const std::string &json)
bool save_to(const std::string &file_path) const
Serialize to a JSON file.
std::optional< PluginInfo > get(const std::string &path) const
Return a cached entry if one exists whose (mtime, size) matches the file on disk today.
Bounded event contracts shared by host ingress and graph-authored nodes.
Definition anticipation_eligibility.hpp:9
Definition scanner.hpp:35
Definition scan_cache.hpp:26
int64_t mtime
Definition scan_cache.hpp:27
int64_t size
Definition scan_cache.hpp:28
PluginInfo info
Definition scan_cache.hpp:29