// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include #include #include #include #include #include #include #include namespace zen { class WideStringBuilderBase; class CasStore; } // namespace zen struct CacheValue { zen::IoBuffer Value; }; /****************************************************************************** /$$ /$$/$$ /$$ /$$$$$$ /$$ | $$ /$$| $$ | $$ /$$__ $$ | $$ | $$ /$$/| $$ | $$ | $$ \__/ /$$$$$$ /$$$$$$| $$$$$$$ /$$$$$$ | $$$$$/ | $$ / $$/ | $$ |____ $$/$$_____| $$__ $$/$$__ $$ | $$ $$ \ $$ $$/ | $$ /$$$$$$| $$ | $$ \ $| $$$$$$$$ | $$\ $$ \ $$$/ | $$ $$/$$__ $| $$ | $$ | $| $$_____/ | $$ \ $$ \ $/ | $$$$$$| $$$$$$| $$$$$$| $$ | $| $$$$$$$ |__/ \__/ \_/ \______/ \_______/\_______|__/ |__/\_______/ Basic Key-Value cache. No restrictions on keys, and values are always opaque binary blobs. ******************************************************************************/ class CacheStore { public: virtual bool Get(std::string_view Key, CacheValue& OutValue) = 0; virtual void Put(std::string_view Key, const CacheValue& Value) = 0; }; /** File system based implementation Emulates the behaviour of UE4 with regards to file system structure, and also adds a file corruption trailer to remain compatible with the file-system based implementation (this should be made configurable) */ class FileCacheStore : public CacheStore { public: FileCacheStore(const char* RootDir, const char* ReadRootDir = nullptr); ~FileCacheStore(); virtual bool Get(std::string_view Key, CacheValue& OutValue) override; virtual void Put(std::string_view Key, const CacheValue& Value) override; private: std::filesystem::path m_RootDir; std::filesystem::path m_ReadRootDir; bool m_IsOk = true; bool m_ReadRootIsValid = false; }; class MemoryCacheStore : public CacheStore { public: MemoryCacheStore(); ~MemoryCacheStore(); virtual bool Get(std::string_view Key, CacheValue& OutValue) override; virtual void Put(std::string_view Key, const CacheValue& Value) override; private: zen::RwLock m_Lock; std::unordered_map m_CacheMap; };