cesium-native  0.41.0
CesiumAsync::SqliteCache Class Reference

Cache storage using SQLITE to store completed response. More...

#include <CesiumAsync/SqliteCache.h>

Inheritance diagram for CesiumAsync::SqliteCache:
CesiumAsync::ICacheDatabase

Public Member Functions

 SqliteCache (const std::shared_ptr< spdlog::logger > &pLogger, const std::string &databaseName, uint64_t maxItems=4096)
 Constructs a new instance with a given databaseName pointing to a database. More...
 
virtual std::optional< CacheItemgetEntry (const std::string &key) const override
 Gets a cache entry from the database. More...
 
virtual bool storeEntry (const std::string &key, std::time_t expiryTime, const std::string &url, const std::string &requestMethod, const HttpHeaders &requestHeaders, uint16_t statusCode, const HttpHeaders &responseHeaders, const gsl::span< const std::byte > &responseData) override
 Store a cache entry in the database. More...
 
virtual bool prune () override
 Remove cache entries from the database to satisfy the database invariant condition (.e.g exired response or LRU). More...
 
virtual bool clearAll () override
 Removes all cache entries from the database. More...
 

Detailed Description

Cache storage using SQLITE to store completed response.

Definition at line 17 of file SqliteCache.h.

Constructor & Destructor Documentation

◆ SqliteCache()

CesiumAsync::SqliteCache::SqliteCache ( const std::shared_ptr< spdlog::logger > &  pLogger,
const std::string &  databaseName,
uint64_t  maxItems = 4096 
)

Constructs a new instance with a given databaseName pointing to a database.

The instance will connect to the existing database or create a new one if it doesn't exist

Parameters
pLoggerThe logger that receives error messages.
databaseNamethe database path.
maxItemsthe maximum number of items should be kept in the database after prunning.

Member Function Documentation

◆ clearAll()

virtual bool CesiumAsync::SqliteCache::clearAll ( )
overridevirtual

Removes all cache entries from the database.

Returns
true if the database was successfully cleared, or false if it could not be pruned due to an errror.

Implements CesiumAsync::ICacheDatabase.

◆ getEntry()

virtual std::optional<CacheItem> CesiumAsync::SqliteCache::getEntry ( const std::string &  key) const
overridevirtual

Gets a cache entry from the database.

If an error prevents checking the database for the key, this function, depending on the implementation, may log the error. However, it should return std::nullopt. It should not throw an exception.

Parameters
keyThe unique key associated with the cache entry.
Returns
The result of the cache lookup, or std::nullopt if the key does not exist in the cache or an error occurred.

Implements CesiumAsync::ICacheDatabase.

◆ prune()

virtual bool CesiumAsync::SqliteCache::prune ( )
overridevirtual

Remove cache entries from the database to satisfy the database invariant condition (.e.g exired response or LRU).

Returns
true if the database was successfully pruned, or false if it could not be pruned due to an errror.

Implements CesiumAsync::ICacheDatabase.

◆ storeEntry()

virtual bool CesiumAsync::SqliteCache::storeEntry ( const std::string &  key,
std::time_t  expiryTime,
const std::string &  url,
const std::string &  requestMethod,
const HttpHeaders requestHeaders,
uint16_t  statusCode,
const HttpHeaders responseHeaders,
const gsl::span< const std::byte > &  responseData 
)
overridevirtual

Store a cache entry in the database.

Parameters
keythe unique key associated with the response
expiryTimethe time point that this response should be expired. An expired response will be removed when prunning the database.
urlThe URL being cached.
requestMethodThe HTTP method being cached.
requestHeadersThe HTTP request headers being cached.
statusCodeThe HTTP response status code being cached.
responseHeadersThe HTTP response headers being cached.
responseDataThe HTTP response being cached.
Returns
true if the entry was successfully stored, or false if it could not be stored due to an error.

Implements CesiumAsync::ICacheDatabase.


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