[erlang-questions] Guidance to a cache mechanism

Jesper Louis Andersen <>
Wed Oct 31 13:03:23 CET 2012


On Oct 31, 2012, at 6:55 AM, Maruthavanan Subbarayan <> wrote:

> Hi Richard,
> 
> I thought of keeping the time stamp as the key in the ets table and maintain that in state when a timeout event occurs. I hope this would help me to delete the entries in ets table with less burden.

Well, ETS tables have two possible configurations that may be of interest to you: by default they are hash-tables, but you can map them as ordered sets. So if you store them as {Key, Payload} you are able to use ets:first/1 to grab the next guy in the queue. And you can quickly walk the table and time out entries. See for instance ets:select_delete/2. You may want, however, to discuss if you want a FIFO or a LIFO order here. FIFO often have the problem that if the queue size goes up, then everybody waits. LIFO stacks have the advantage that long waiters will wait longer.

Jesper Louis Andersen
  Erlang Solutions Ltd., Copenhagen






More information about the erlang-questions mailing list