@@ -41,21 +41,48 @@ class CachedFileStream {
41
41
using AddStreamFn = std::function<Expected<std::unique_ptr<CachedFileStream>>(
42
42
unsigned Task, const Twine &ModuleName)>;
43
43
44
- // / This is the type of a file cache. To request an item from the cache, pass a
45
- // / unique string as the Key. For hits, the cached file will be added to the
46
- // / link and this function will return AddStreamFn(). For misses, the cache will
47
- // / return a stream callback which must be called at most once to produce
48
- // / content for the stream. The file stream produced by the stream callback will
49
- // / add the file to the link after the stream is written to. ModuleName is the
50
- // / unique module identifier for the bitcode module the cache is being checked
51
- // / for.
44
+ // / This is a callable that manages file caching operations. It accepts a task
45
+ // / ID \p Task, a unique key \p Key, and a module name \p ModuleName, and
46
+ // / returns AddStreamFn(). This function determines whether a cache hit or miss
47
+ // / occurs and handles the appropriate actions.
48
+ using FileCacheFunction = std::function<Expected<AddStreamFn>(
49
+ unsigned Task, StringRef Key, const Twine &ModuleName)>;
50
+
51
+ // / This type represents a file cache system that manages caching of files.
52
+ // / It encapsulates a caching function and the directory path where the cache is
53
+ // / stored. To request an item from the cache, pass a unique string as the Key.
54
+ // / For hits, the cached file will be added to the link and this function will
55
+ // / return AddStreamFn(). For misses, the cache will return a stream callback
56
+ // / which must be called at most once to produce content for the stream. The
57
+ // / file stream produced by the stream callback will add the file to the link
58
+ // / after the stream is written to. ModuleName is the unique module identifier
59
+ // / for the bitcode module the cache is being checked for.
52
60
// /
53
61
// / Clients generally look like this:
54
62
// /
55
63
// / if (AddStreamFn AddStream = Cache(Task, Key, ModuleName))
56
64
// / ProduceContent(AddStream);
57
- using FileCache = std::function<Expected<AddStreamFn>(
58
- unsigned Task, StringRef Key, const Twine &ModuleName)>;
65
+ // /
66
+ // / CacheDirectoryPath stores the directory path where cached files are kept.
67
+ struct FileCache {
68
+ FileCache (FileCacheFunction CacheFn, const std::string &DirectoryPath)
69
+ : CacheFunction(std::move(CacheFn)), CacheDirectoryPath(DirectoryPath) {}
70
+ FileCache () = default ;
71
+
72
+ Expected<AddStreamFn> operator ()(unsigned Task, StringRef Key,
73
+ const Twine &ModuleName) {
74
+ assert (isValid () && " Invalid cache function" );
75
+ return CacheFunction (Task, Key, ModuleName);
76
+ }
77
+ const std::string &getCacheDirectoryPath () const {
78
+ return CacheDirectoryPath;
79
+ }
80
+ bool isValid () const { return static_cast <bool >(CacheFunction); }
81
+
82
+ private:
83
+ FileCacheFunction CacheFunction = nullptr ;
84
+ std::string CacheDirectoryPath;
85
+ };
59
86
60
87
// / This type defines the callback to add a pre-existing file (e.g. in a cache).
61
88
// /
0 commit comments