Last active
March 7, 2018 05:26
-
-
Save RoshanNindrai/bb95ac04ee881692b416fa7ad46f0398 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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