Skip to content

Commit

Permalink
Merge pull request #19 from jarrodparkes/master
Browse files Browse the repository at this point in the history
update readme example
  • Loading branch information
onmyway133 authored Jan 24, 2021
2 parents c7230d6 + 1324697 commit e1f0b2f
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
❤️ Support my apps ❤️
❤️ Support my apps ❤️

- [Push Hero - pure Swift native macOS application to test push notifications](https://onmyway133.com/pushhero)
- [PastePal - Pasteboard, note and shortcut manager](https://onmyway133.com/pastepal)
Expand Down Expand Up @@ -36,15 +36,22 @@ EasyStash is an easy and lightweight persistence framework in Swift. With simple

The main and only class is `Storage` which encapsulates memory and disk cache. All operations involving disk are error prone, we need to handle error explicitly.

With `Options`, we can customize `folder` name, `searchPathDirectory`, `encoder` and `decoder` for `Codable`
With `Options`, we can customize `folder` name, `searchPathDirectory`, `encoder` and `decoder` for `Codable`. By default, `folder` and `searchPathDirectory` specify that files will be saved at `/Library/Application Support/{BUNDLE_ID}/Default/`

```swift
let options = Options()
var storage: Storage? = nil

var options: Options = Options()
options.folder = "Users"
storage = try! Storage(options: options)

try storage.save(image, forKey: "image")
try storage.save(users, forKey: "codable")
storage = try? Storage(options: options)

do {
try storage?.save(image, forKey: "image")
try storage?.save(users, forKey: "codable")
} catch {
print(error)
}
```

Memory cache is checked first before doing disk operations, so we won't hit disk that often.
Expand Down Expand Up @@ -144,7 +151,7 @@ DispatchQueue.global().async {
do {
try storage.save(largeImage, forKey: "large_image")
} catch {

}
}
```
Expand Down

0 comments on commit e1f0b2f

Please sign in to comment.