|
Haio 0.2.X
Homebrew Asset IO/CDN
|
#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) |
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.
| using Haio::Cdn::Cache::Producer = std::function<boost::asio::awaitable<Result<CacheEntry>>()> |
Definition at line 79 of file haio_cache.hpp.
|
default |

| 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.
| bool Haio::Cdn::Cache::enabled | ( | ) | const |
| 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.