Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Starting a timer for each item in the cache can be resource intensive and might even reach the capabilities of the VM with a high enough number of items.
Add an option to batch the send_after/3 calls per TTL interval by buffering them for a while in the gen_server's state and sent in one batch per TTL interval. The configuration variable is called:
buffer_limit
and denotes the maximum length of this internal buffer.A regular tick event is also added to make sure that the TTL timers are started even when the number of new items do not fill the buffer in a given tick interval set by the configuration variable:
expiry_tick_ms
.To keep the implementation simple all the buffered TTL intervals are emptied at each tick.
By not setting the new configuration variable
buffer_limit
the behaviour remains as it was before: an expiration timer is started for each new item when expriry set other than infinity.