mirror of
https://github.com/mailscope/kumomta.git
synced 2026-09-06 02:28:56 +00:00
If many calls are made to the memoized function with the same parameters at the time that the cache is empty/expired, then each of those concurrent calls will proceed to compute and populate the cache. This is known as a thundering herd, and can be painful if the amount of work performed by the cache population function is high, or alternatively, if the level of concurrency is high and some system resource is required to satisfy the call, this can put the system under higher pressure. This commit adds a simple mechanism to mitigate this: each combination of cache and cache parameters is paired with an optional semaphore that is used to constrain concurrency to a single call. This could be a mutex, but using a semaphore allows future explicit control over the concurrency level.