#pragma once #include #include #include #include #include #include #include #include #include namespace CesiumAsync { class AsyncSystem; /** * @brief A decorator for an {@link IAssetAccessor} that caches requests and * responses in an {@link ICacheDatabase}. * * This can be used to improve asset loading performance by caching assets * across runs. */ class CachingAssetAccessor : public IAssetAccessor { public: /** * @brief Constructs a new instance. * * @param pLogger The logger that receives messages about the status of this * instance. * @param pAssetAccessor The underlying {@link IAssetAccessor} used to * retrieve assets that are not in the cache. * @param pCacheDatabase The database in which to cache requests and * responses. * @param requestsPerCachePrune The number of requests to handle before each * {@link ICacheDatabase::prune} of old cached results from the database. */ CachingAssetAccessor( const std::shared_ptr& pLogger, const std::shared_ptr& pAssetAccessor, const std::shared_ptr& pCacheDatabase, int32_t requestsPerCachePrune = 10000); virtual ~CachingAssetAccessor() noexcept override; /** @copydoc IAssetAccessor::get */ virtual Future> get(const AsyncSystem& asyncSystem, const std::string& url, const std::vector& headers) override; virtual Future> request( const AsyncSystem& asyncSystem, const std::string& verb, const std::string& url, const std::vector& headers, const std::span& contentPayload) override; /** @copydoc IAssetAccessor::tick */ virtual void tick() noexcept override; private: int32_t _requestsPerCachePrune; std::atomic _requestSinceLastPrune; std::shared_ptr _pLogger; std::shared_ptr _pAssetAccessor; std::shared_ptr _pCacheDatabase; ThreadPool _cacheThreadPool; CESIUM_TRACE_DECLARE_TRACK_SET(_pruneSlots, "Prune cache database") }; } // namespace CesiumAsync