FIFOCache member exempted from expulsion after evict
Calling evict causes FIFOCache to lose track of one of the remaining
keys, so that member will never expire. Gradually, nearly the entire
FIFOCache may become occupied by permanent members.
FIFOCache keeps a threshold and a sequence of keys. seed fills the
sequence fully to the threshold – the postcondition on
fifo-cache-factory attests to this invariant –
and miss holds the sequence length steady by dropping the first key
when adding a new last key. But evict shortens the key sequence.
And miss, although it always drops the oldest key, removes the
corresponding map entry only if the map's size meets or exceeds the
threshold. The problem arises after evict shortens the key
sequence: the next call to miss throws away the oldest key without
removing its entry from the map. As a result, an old thing, which
should have been removed, remains forever.
The toString of FIFOCache helpfully displays both the map and the
key sequence, so we can observe as the sequence loses keys:
Now the map is correct but the key sequence has forgotten :a; it will
never be expired. We will add :d and observe FIFOCache discarding
the new :c instead of the old :a:
The following silly loop puts numbers 0 through 999 into a FIFOCache
and evicts half of them immediately after adding them. This pattern
soon exhausts the key sequence – leaving only one slot turning over
according to the FIFO rule. The final println shows 999 occupying
that slot while the oldest items (1 to 61) remain in the FIFOCache.
Will be in next release. Thank you for the detailed repro case!