Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala disk based Map

I have a large map that won't fit in memory and I thus want it to live on the disk. I have the following options:

  1. Use a pure Java library like MapDB: This works but I don't get Scala collections sugar like getOrElseUpdate and ++= and the apply/update methods. I could create my own wrapper class around MapDB in Scala but I really don't want to manually implement all the Map traits.
  2. Use something like redis/memcached: I could not find a good scala library that gave me the Map traits for redis or memcached. This may be the better performance solution but it introduces a complexity of running a db

So is there any nice scala only library that implements the Scala collection sugars for maps and yet it falls back on disk and/or a key-value store for large maps?

like image 588
pathikrit Avatar asked Nov 01 '25 07:11

pathikrit


1 Answers

Answered my own question

import collection.mutable
import org.mapdb.DBMaker
import collection.JavaConversions._

val cache: mutable.Map[String, Seq[String]] = DBMaker.newTempHashMap[String, Seq[String]]()
like image 63
pathikrit Avatar answered Nov 04 '25 02:11

pathikrit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!