Skip to content

Instantly share code, notes, and snippets.

@thexande
Created December 20, 2018 05:03
Show Gist options
  • Save thexande/b43a77daf0f43fa8d2a16741386fd248 to your computer and use it in GitHub Desktop.
Save thexande/b43a77daf0f43fa8d2a16741386fd248 to your computer and use it in GitHub Desktop.
@testable import Apollo
final class InMemoryNormalizedCache: NormalizedCache {
private var records: RecordSet
init(records: RecordSet = RecordSet()) {
self.records = records
}
func loadRecords(forKeys keys: [CacheKey]) -> Promise<[Record?]> {
let records = keys.map { self.records[$0] }
return Promise(fulfilled: records)
}
func merge(records: RecordSet) -> Promise> {
return Promise(fulfilled: self.records.merge(records: records))
}
func clear() -> Promise {
records.clear()
return Promise(fulfilled: ())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment