cesium-native  0.41.0
CesiumAsync::CachingAssetAccessor Class Reference

A decorator for an IAssetAccessor that caches requests and responses in an ICacheDatabase. More...

#include <CesiumAsync/CachingAssetAccessor.h>

Inheritance diagram for CesiumAsync::CachingAssetAccessor:
CesiumAsync::IAssetAccessor

Public Member Functions

 CachingAssetAccessor (const std::shared_ptr< spdlog::logger > &pLogger, const std::shared_ptr< IAssetAccessor > &pAssetAccessor, const std::shared_ptr< ICacheDatabase > &pCacheDatabase, int32_t requestsPerCachePrune=10000)
 Constructs a new instance. More...
 
virtual Future< std::shared_ptr< IAssetRequest > > get (const AsyncSystem &asyncSystem, const std::string &url, const std::vector< THeader > &headers) override
 Starts a new request for the asset with the given URL. The request proceeds asynchronously without blocking the calling thread. More...
 
virtual Future< std::shared_ptr< IAssetRequest > > request (const AsyncSystem &asyncSystem, const std::string &verb, const std::string &url, const std::vector< THeader > &headers, const gsl::span< const std::byte > &contentPayload) override
 Starts a new request to the given URL, using the provided HTTP verb and the provided content payload. More...
 
virtual void tick () noexcept override
 Ticks the asset accessor system while the main thread is blocked. More...
 

Additional Inherited Members

- Public Types inherited from CesiumAsync::IAssetAccessor
typedef std::pair< std::string, std::string > THeader
 An HTTP header represented as a key/value pair.
 

Detailed Description

A decorator for an IAssetAccessor that caches requests and responses in an ICacheDatabase.

This can be used to improve asset loading performance by caching assets across runs.

Definition at line 25 of file CachingAssetAccessor.h.

Constructor & Destructor Documentation

◆ CachingAssetAccessor()

CesiumAsync::CachingAssetAccessor::CachingAssetAccessor ( const std::shared_ptr< spdlog::logger > &  pLogger,
const std::shared_ptr< IAssetAccessor > &  pAssetAccessor,
const std::shared_ptr< ICacheDatabase > &  pCacheDatabase,
int32_t  requestsPerCachePrune = 10000 
)

Constructs a new instance.

Parameters
pLoggerThe logger that receives messages about the status of this instance.
pAssetAccessorThe underlying IAssetAccessor used to retrieve assets that are not in the cache.
pCacheDatabaseThe database in which to cache requests and responses.
requestsPerCachePruneThe number of requests to handle before each ICacheDatabase::prune of old cached results from the database.

Member Function Documentation

◆ get()

virtual Future<std::shared_ptr<IAssetRequest> > CesiumAsync::CachingAssetAccessor::get ( const AsyncSystem asyncSystem,
const std::string &  url,
const std::vector< THeader > &  headers 
)
overridevirtual

Starts a new request for the asset with the given URL. The request proceeds asynchronously without blocking the calling thread.

Parameters
asyncSystemThe async system used to do work in threads.
urlThe URL of the asset.
headersThe headers to include in the request.
Returns
The in-progress asset request.

Implements CesiumAsync::IAssetAccessor.

◆ request()

virtual Future<std::shared_ptr<IAssetRequest> > CesiumAsync::CachingAssetAccessor::request ( const AsyncSystem asyncSystem,
const std::string &  verb,
const std::string &  url,
const std::vector< THeader > &  headers,
const gsl::span< const std::byte > &  contentPayload 
)
overridevirtual

Starts a new request to the given URL, using the provided HTTP verb and the provided content payload.

The request proceeds asynchronously without blocking the calling thread.

Parameters
asyncSystemThe async system used to do work in threads.
verbThe HTTP verb to use, such as "POST" or "PATCH".
urlThe URL of the asset.
headersThe headers to include in the request.
contentPayloadThe payload data to include in the request.
Returns
The in-progress asset request.

Implements CesiumAsync::IAssetAccessor.

◆ tick()

virtual void CesiumAsync::CachingAssetAccessor::tick ( )
overridevirtualnoexcept

Ticks the asset accessor system while the main thread is blocked.

If the asset accessor is not dependent on the main thread to dispatch requests, this method does not need to do anything.

Implements CesiumAsync::IAssetAccessor.


The documentation for this class was generated from the following file: