Skip to content

Commit 96f7667

Browse files
committed
Use TrieMap
1 parent c9efede commit 96f7667

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/main/scala/06/d.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@ object d {
44
// #example1
55
import unfiltered.request._
66
import unfiltered.response._
7+
import scala.collection.concurrent.TrieMap
78

89
object SillyStore extends unfiltered.filter.Plan {
9-
@volatile private var store = Map.empty[String, Array[Byte]]
10+
private val store: TrieMap[String, Array[Byte]] =
11+
TrieMap.empty[String, Array[Byte]]
12+
1013
def intent = {
1114
case req @ Path(Seg("record" :: id :: Nil)) => req match {
1215
case GET(_) =>
1316
store.get(id).map(ResponseBytes.apply).getOrElse {
1417
NotFound ~> ResponseString("No record: " + id)
1518
}
1619
case PUT(_) =>
17-
SillyStore.synchronized {
18-
store = store + (id -> Body.bytes(req))
19-
}
20+
store += (id -> Body.bytes(req))
2021
Created ~> ResponseString("Created record: " + id)
2122
case _ =>
2223
MethodNotAllowed ~> ResponseString("Must be GET or PUT")

0 commit comments

Comments
 (0)