Skip to content

Commit

Permalink
Merge pull request #246 from rubanm/readthrough_keysfix
Browse files Browse the repository at this point in the history
Read through store - do not query backing store when no cache miss
  • Loading branch information
ianoc committed Dec 8, 2014
2 parents 7cb17e5 + b1f9fd3 commit def3906
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,17 @@ class ReadThroughStore[K, V](backingStore: ReadableStore[K, V], cache: Store[K,
val hits = responses.filter { !_._2.isEmpty }
val missedKeys = responses.filter { _._2.isEmpty }.keySet

FutureOps.mapCollect(backingStore.multiGet(missedKeys ++ failedKeys)).flatMap { storeResult =>
// write fetched keys to cache, best effort
mutex.acquire.flatMap { p =>
FutureOps.mapCollect(cache.multiPut(storeResult))(FutureCollector.bestEffort[(K1, Unit)])
.map { u => hits ++ storeResult }
.ensure { p.release }
val remaining = missedKeys ++ failedKeys
if (remaining.isEmpty) {
Future.value(hits) // no cache misses
} else {
FutureOps.mapCollect(backingStore.multiGet(remaining)).flatMap { storeResult =>
// write fetched keys to cache, best effort
mutex.acquire.flatMap { p =>
FutureOps.mapCollect(cache.multiPut(storeResult))(FutureCollector.bestEffort[(K1, Unit)])
.map { u => hits ++ storeResult }
.ensure { p.release }
}
}
}
}
Expand Down

0 comments on commit def3906

Please sign in to comment.