schuderer/mllaunchpad

Make cache LRU

schuderer opened this issue · 0 comments

Caching in DataSources (as enabled with an ‘expires’ value other than 0), can be made more fit for purpose by following the Last Recently Used principle instead of, currently, Last Recently Added. That way, the items that are requested more frequently tend to stay in the cache longer. Currently, if an item has been added a longer time ago, it will be removed if enough new items have been added to push it out of the cache FIFO.

This should be trivial to achieve using OrderDict’s move_to_end method in the OrderedDict subclass’ getitem to move the last requested item to the “last added” (end) position of the dict.

However, care must be taken to test this properly and differentiate it from the previous FIFO style in the unit tests.