0

Is there any built LRU Memory cache class in scala with a size limit and key eviction based on LRU/LFU? I've tried https://doc.akka.io/docs/akka-http/current/common/caching.html but it seems to be a bit complicated with wrapped futures.

Thanks.

Pratap D
  • 311
  • 3
  • 7
  • 14
  • if you want this to be thread-safe (probably) and referential transparent (maybe), go the `Cats Effect` way: https://gist.github.com/ChristopherDavenport/8364fa2ca14557fce12baca6cb38d5b8That is, if you're already invested in the ecosystem. If not you're probably put off by this example, and you could have a look at a Java library maybe? https://stackoverflow.com/questions/23772102/lru-cache-in-java-with-generics-and-o1-operations – Raf Nov 03 '21 at 08:04

1 Answers1

1

Caffeine should be a good way to do that : https://github.com/ben-manes/caffeine

C4stor
  • 8,355
  • 6
  • 29
  • 47
  • I have tried scaffeine, but getting this error java.lang.UnsupportedClassVersionError: com/github/blemale/scaffeine/CacheLoaderAdapter has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0 – Pratap D Nov 09 '21 at 07:37
  • 1
    Caffeine 3+ is for java 11, for java 8, you should use caffeine 2+, the latest being 2.9.2 – C4stor Nov 09 '21 at 10:25