type Item = String type Units = Long val cache = TrieMap[Item, Units]() def updateSoldUnits(item: Item, soldUnits: Units): Unit = { cache.putIfAbsent(item, 0) var oldValue = cache(item) var newValue = oldValue + soldUnits while (!cache.replace(item, oldValue, newValue) { oldValue = cache(item) newValue = oldValue + soldUnits } }