|
Haio 0.2.X
Homebrew Asset IO/CDN
|
#include <cache.hpp>
Public Member Functions | |
| ClientQuota (size_t perWindow, std::chrono::seconds window) | |
| bool | mayStore (const std::string &client) |
how many entries one address may create per window.
the limit is on creating, never on reading: what it answers is one caller filling the cache with keys nobody else wants and evicting everyone else on the way.
| Haio::Cdn::Detail::ClientQuota::ClientQuota | ( | size_t | perWindow, |
| std::chrono::seconds | window ) |
| bool Haio::Cdn::Detail::ClientQuota::mayStore | ( | const std::string & | client | ) |
the quota counts entries created, not requests served, and it refills every window. going over does not fail anything: the answer is produced and returned, it is only not stored, so an address that asks for ten thousand different sizes pays for them itself instead of evicting everybody else.
the table is keyed by address, so a caller with many addresses grows it. expired rows are dropped on the way past, and if it still runs away the whole table is cleared: everyone gets a fresh quota, which is far better than an allocation nobody bounds.