Skip to content

Instantly share code, notes, and snippets.

@RoshanNindrai
Last active March 7, 2018 05:26
Show Gist options
  • Save RoshanNindrai/bb95ac04ee881692b416fa7ad46f0398 to your computer and use it in GitHub Desktop.
Save RoshanNindrai/bb95ac04ee881692b416fa7ad46f0398 to your computer and use it in GitHub Desktop.
/// Manager class responsible of retriving data
final class DataManager {
/// Memory Cache responsible for maintaining data in memory
var memory = MemoryCache()
/// Disc Cache responsible for maintaining data in memory
var disc = DiscCache()
/// To get value from persistence for a specific key, data is first checked in memory,
/// followed by disc. If data isnot found `nil` is returned
func get(_ key: key) -> Value? {
if let value = memory.get(key) { return value }
else if let value = disc.get(key) { return value }
else { return nil }
}
/// To set value into persistence for a specific key, data is first saved in memory,
/// followed by disc.
func set(_ key: key, _ value: Value) -> Void {
memory.set(key, value)
disc.set(key, value)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment