Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

EthanLipnik/Sebu

Repository files navigation

Sebu

Easy caching for codable objects.

How does it store?

Sebu uses JSON to store objects in the app's cache directory.

Usage

Save

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

Get

if let cache: [Tweet] = try? Sebu.default.get(withName: "homeTimeline") {
  self.tweets = cache
}

Clear cache

All cache

Sebu.default.clearAll()

Clear certain object

Sebu.default.clear("homeTimeline")