0

I need a persistent cache that holds up to several million 6 character base36 strings and has the following behavior: - When clients retrieve N strings from the cache, they are retrieved in the order of the base36 value e.g. AAAAAA then AAAAAB etc. - When strings are retrieved they are also removed from the cache so no other client will receive the same strings.

I am currently using MapDB as my persistent cache (I'd use EHCache but it requires a license for persistent storage).

MapDB gives me a Map to which I can put/get elements from and it handles the persisting to disk.

I have noticed that Java's ConcurrentSkipListMap class would help in my problem since it provides ordering and I can also call the pollFirstEntry method to retrieve/remove elements in order.

I am not sure how I can use this with MapDB though. Does anyone have any advice that can help me achieve the behavior that I have outlined?

Thanks

sam
  • 2,469
  • 8
  • 37
  • 57

1 Answers1

1

What you're describing doesn't sound like what most people would consider a cache. A cache is essentially a shared Map, with keys mapping to values, and you'd never remove on a read because you want your cache to contain the most popular items (that's what it's for).

What you're describing (ordered set of items, consumed by clients in a fixed order) is much more like a work queue. Rather than looking at cache solutions try persistent queues like RabbitMQ, Kafka, bigqueue, etc.

adamreeve
  • 376
  • 1
  • 4