Does anyone know of a prebuilt least-recently-used algorithm/cache in Java that I can pinch? I have a nagging feeling that there should be a util collection that I can use to make things easy but it escapes me at the moment…
java.util.LinkedHashMap @since 1.4
Contains full instructions on turning it into an LRU cache.
Pretty easy.
EDIT: that wasn’t meant to be patronising, just making it clear that although it’s not “java.util.LRUCache” it’s only 5 mins to finish it off…
Aha, I knew there would be an easy way of doing it somehow, definatly less work than with a TreeSet as I was planning.
Cheers!