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

#include <cache.hpp>

Classes

struct  Pending

Public Types

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

Public Member Functions

 SingleFlight (boost::asio::any_io_executor executor)
boost::asio::awaitable< Result< CacheEntry > > run (const std::string &key, const Producer &produce)

Detailed Description

one producer per key, however many callers ask at once.

it knows nothing about caching: a burst on a key reaches the producer once whether or not the answer is kept afterwards, which is why turning the cache off does not turn an amplifier back on.

Definition at line 23 of file cache.hpp.


Class Documentation

◆ Haio::Cdn::Detail::SingleFlight::Pending

struct Haio::Cdn::Detail::SingleFlight::Pending

the answer lives here rather than being read back from a store, so waiters are served even when nothing is being stored.

Definition at line 15 of file deduplication.cpp.

Class Members
optional< Result< CacheEntry > > answer
shared_ptr< steady_timer > timer

Member Typedef Documentation

◆ Producer

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

Definition at line 25 of file cache.hpp.

Constructor & Destructor Documentation

◆ SingleFlight()

Haio::Cdn::Detail::SingleFlight::SingleFlight ( boost::asio::any_io_executor executor)
explicit

Definition at line 20 of file deduplication.cpp.

Member Function Documentation

◆ run()

asio::awaitable< Result< CacheEntry > > Haio::Cdn::Detail::SingleFlight::run ( const std::string & key,
const Producer & produce )

runs the producer, or waits for whoever is already running it for this key

the map carries no lock because the cdn runs one io_context on one thread, so a coroutine only ever yields at a co_await and never mid update. putting the server on a thread pool means revisiting exactly this.

the timer has to be cancelled however this ends, including by an exception, or every waiter parks forever. the answer is written before the wake, so a waiter that runs the instant it is cancelled already has something to read.

Definition at line 27 of file deduplication.cpp.

Here is the call graph for this function:

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