Skip to content

vinaynair/EhCacheAsScalaMap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

EhCache as Scala Map

Exposing relevant EhCache features as a scala mutable Map provides interesting possibilities for use & integration. Note by merely switching the ehcache implementation with BigMemory, we can exploit the same set of features with local offheap in-memory store as well as clustered caches.

Apart from the obvious type-safety with a Map, other obvious features include:-

Add

val m = new CacheAsMap[Int, String]
//add key+value pair using the following syntax
m(1) = "a"
//or
m += (2 -> "b")
//or since its mutable
m+(3->"c")
//or to add 2 cache maps together
val n = new CacheAsMap[Int,String]()
n(4)="d"
n++=m

Remove

m-=2
//or, remove more than one key at a time
n -=(1,2)

Get

println(m(1))

Filter

val m = new CacheAsMap[String, String]()
//add elements
m("apple") = "fruit"
m("potato") = "vegetable"
m("grapes") = "fruit"
//now filter

//For a key value pair, filter results on a value, for example, find all fruits
val filteredResults=m.filter { case(key,value) => value.equals("fruit") }

Transform the values using a closure

 val m = new CacheAsMap[Int,Int]()
    m(1)=1
    m(2)=2
    m(3)=3
    // increment all the values by 1
    m transform ( (k,v) => v+1 )

Building & running samples

Use SBT and run the unit tests

TODO

  • Figure how to have a BigMemory profile within SBT along with the opensource ehcache to test and try BigMemory features

About

EhCache as scala mutable Map

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages