Haio 0.2.X
Homebrew Asset IO/CDN
Loading...
Searching...
No Matches
Haio::Cdn::Cache Class Reference

#include <haio_cache.hpp>

Classes

struct  Impl

Public Types

using Producer = std::function<boost::asio::awaitable<Result<CacheEntry>>()>

Public Member Functions

 Cache ()=default
 Cache (CacheConfig config, size_t maxEntriesByIp, boost::asio::any_io_executor executor)
bool enabled () const
boost::asio::awaitable< Result< CacheEntry > > fetch (std::string key, std::string client, Producer produce)

Detailed Description

the store, plus the part that keeps one key from being produced many times at once.

the two are independent on purpose: deduplication needs no store and stays on even when no cache is configured, because a burst on one key sending one upstream request per caller is an amplifier whether or not the answer is kept afterwards.

Definition at line 77 of file haio_cache.hpp.

Member Typedef Documentation

◆ Producer

using Haio::Cdn::Cache::Producer = std::function<boost::asio::awaitable<Result<CacheEntry>>()>

Definition at line 79 of file haio_cache.hpp.

Constructor & Destructor Documentation

◆ Cache() [1/2]

Haio::Cdn::Cache::Cache ( )
default
Here is the call graph for this function:

◆ Cache() [2/2]

Haio::Cdn::Cache::Cache ( CacheConfig config,
size_t maxEntriesByIp,
boost::asio::any_io_executor executor )

maxEntriesByIp is spelled in [security] rather than in [cache], because it is a limit on a caller and not on the store. it is passed rather than copied into CacheConfig so that the number lives in exactly one place.

Definition at line 49 of file cache.cpp.

Member Function Documentation

◆ enabled()

bool Haio::Cdn::Cache::enabled ( ) const

true when entries are kept; deduplication happens either way

Definition at line 55 of file cache.cpp.

◆ fetch()

asio::awaitable< Result< CacheEntry > > Haio::Cdn::Cache::fetch ( std::string key,
std::string client,
Producer produce )

returns the stored entry, or runs the producer once and stores what it made.

client is the address the request came from, and it is only used to decide whether the result may be stored. reading is always free: the limit is there to stop one caller from filling the cache with keys nobody else will ask for, and evicting everyone else's entries on the way.

Definition at line 59 of file cache.cpp.


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