I need a circular buffer implementation that supports readable readers. My use case:
In my code, I collect log messages. In the end, the user can visit a page that displays them nicely formatted. To make sure the messages do not fill the RAM, I need a fixed-size FIFO structure. If the user does not visit the page for a long time, the messages will be deleted. This is normal.
As long as the user remains on the page, new log messages should be added to the page. Through JavaScript, the user can determine how many messages need to be saved. This is completely independent of the size of the buffer in my application. Therefore, I need a reader in the data structure, which I can use to iterate over any new elements.
If the user reloads the page or loads it for the first time, I need to set the reader to the oldest element in FIFO.
As you add messages, the reader should be updated. If the browser cannot quickly receive new messages, the reader must ultimately point to the oldest message in FIFO. This means that the user can skip a couple of messages. This is not ideal, but it should be an unusual case. If the reader could tell me "missed 5 posts", that would be great, but I can live without it.
Do you know an existing implementation that offers this?
Aaron digulla
source share