Skip to content

Conversation

@aboroska
Copy link

@aboroska aboroska commented Sep 4, 2023

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.

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.
@aboroska
Copy link
Author

aboroska commented Sep 4, 2023

This change would make simple_cache less "simple". I argue that it is still simple enough, especially compared to other implementations, though I am not offended if it is decided to not fit in the "simple" category.

Co-authored-by: Jonathan Prouse <jonathan@gameanalytics.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant