-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- dependency management tweaks - tests - readme update
- Loading branch information
Showing
3 changed files
with
61 additions
and
18 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,51 @@ | ||
Simple URL load caching service that allows to directly cache responses without having to rely on predetermined URLSession caching strategies. | ||
- expiration policies support | ||
- disk and memory storage | ||
`NetworkCacheService` is a simple URL load caching service that allows to directly cache responses without having to rely on predetermined URLSession caching strategies. | ||
|
||
##Features | ||
|
||
- Expiration policies support | ||
- Disk and memory storage | ||
- Full thread safety | ||
|
||
##Usage | ||
|
||
###Caching of network response models: | ||
|
||
```swift | ||
URLSession.shared.dataTask(with: url) { [cacheService] data, response, error in | ||
guard let response, let data else { | ||
return | ||
} | ||
|
||
do { | ||
let networkModel = try JSONDecoder().decode(ResponseNetworkModel.self, from: data) | ||
|
||
cacheService.cacheItem(networkModel, with: response, for: url, policies: .nonExpirable) | ||
} | ||
catch { | ||
} | ||
}.resume() | ||
``` | ||
|
||
###Reading of previously cached models: | ||
|
||
```swift | ||
let modelOrNil = cacheService.readItem(of: ResponseNetworkModel.self, for: url) | ||
``` | ||
|
||
## Integration | ||
|
||
### [Swift Package Manager](https://github.com/apple/swift-package-manager) | ||
|
||
Use Swift Package Manager and add dependency to `Package.swift` file. | ||
|
||
```swift | ||
dependencies: [ | ||
.package(url: "https://github.com/ivasilyeu/NetworkCacheService.git", .upToNextMajor(from: "1.0.0")) | ||
] | ||
``` | ||
|
||
Alternatively, in Xcode select `File > Add Package Dependencies…` and add NetworkCacheService repository URL: | ||
|
||
``` | ||
https://github.com/ivasilyeu/NetworkCacheService.git | ||
``` |
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
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