serby/ttl-lru-cache — pull request #3 by mjor (2012-08-06 11:08:03+00:00)
Title: Update LRU cache on item retrieval (hacky)

I've submitted this pull request to "solve" issue #2 for now, but we should have a chat about how the cache is structured when you have the time.

Because `lru.shift()` is used during GC, all items in the `cache` object will have mismatched `.lruId` properties as soon as a single item is deleted from the cache. This will result in items being randomly exempt from the LRU check (this should be considered a memory leak).

Also, `delete array[index]` is used in a few places in the project. This won't actually remove the element at `index`, but rather set it to `undefined`. This will lead to strange behaviour when clearing the LRU. During LRU clears, `lru.shift()` will fetch these, now undefined, elements which point to items which at this point have already been removed from the cache.

Finally, when overwriting an existing key, the previous LRU entry isn't removed or invalidated, causing the new item to now have two (or more) items in the LRU queue. This will again lead to inconsistent behaviour when clearing the LRU.

I stumbled upon a few other issues, but they are primarily performance related.