|
Haio 0.2.X
Homebrew Asset IO/CDN
|
#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) |
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.
| 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 | |
| using Haio::Cdn::Detail::SingleFlight::Producer = std::function<boost::asio::awaitable<Result<CacheEntry>>()> |
|
explicit |
Definition at line 20 of file deduplication.cpp.
| 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.
