#pragma once #include #include #include #include #include #include struct Config; struct IndexFile; struct ICacheManager { struct FakeCacheEntry { std::string path; std::string content; std::string json; }; static std::shared_ptr Make(Config* config); static std::shared_ptr MakeFake( const std::vector& entries); virtual ~ICacheManager(); // Tries to load a cache for |path|, returning null if there is none. The // cache loader still owns the cache. IndexFile* TryLoad(const std::string& path); // Takes the existing cache or loads the cache at |path|. May return null if // the cache does not exist. std::unique_ptr TryTakeOrLoad(const std::string& path); // Takes the existing cache or loads the cache at |path|. Asserts the cache // exists. std::unique_ptr TakeOrLoad(const std::string& path); virtual void WriteToCache(IndexFile& file) = 0; virtual optional LoadCachedFileContents( const std::string& path) = 0; // Iterate over all loaded caches. void IterateLoadedCaches(std::function fn); protected: virtual std::unique_ptr RawCacheLoad(const std::string& path) = 0; std::unordered_map> caches_; };