Easy caching for codable objects.
Sebu uses JSON to store objects in the app's cache directory.
Save object
let tweets = [Tweet()] // Your own object(s)
try Sebu.default.set(tweets,
withName: "homeTimeline") // Your own cache name (overwrites by default)
Save object with expiration
try Sebu.default.set(tweets,
withName: "homeTimeline",
expiration: Calendar.current.date(byAdding: .minute, value: 5, to: Date())) // Expires in 5 minutes from now
if let cache: [Tweet] = try? Sebu.default.get(withName: "homeTimeline") {
self.tweets = cache
}
All cache
Sebu.default.clearAll()
Clear certain object
Sebu.default.clear("homeTimeline")