youtube/spfjs — pull request #78 by DavidCPhillips (2014-08-29 17:59:27+00:00)
Title: Update the cache counters when accessed.

This change will modify each cache entry whenever they're accessed to give it a new counter. The cache ends up having a semi-LRU type behavior.

As a consequence, counters can now be in a state where they're not consecutive. This requires a change to the collect method to grab the minimum values until the cache is under the max instead of testing for a strict difference. The new algorithm is n^2, but the vast majority of collects will only need to remove one element (meaning only one pass is required), so I didn't feel it was worth it to put in a better implementation which would require either a new heap or a quick select implementation.

Progress on #75.