Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/basvankuijck/perfect-cache
Simple Perfect swift file caching
https://github.com/basvankuijck/perfect-cache
cache perfect swift
Last synced: 22 days ago
JSON representation
Simple Perfect swift file caching
- Host: GitHub
- URL: https://github.com/basvankuijck/perfect-cache
- Owner: basvankuijck
- Created: 2017-07-19T08:28:08.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-07-21T08:48:03.000Z (over 7 years ago)
- Last Synced: 2024-10-05T00:22:38.617Z (about 1 month ago)
- Topics: cache, perfect, swift
- Language: Swift
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[![forthebadge](http://forthebadge.com/images/badges/made-with-swift.svg)](http://forthebadge.com)
[![forthebadge](http://forthebadge.com/images/badges/as-seen-on-tv.svg)](http://forthebadge.com)# Perfect-Cache
Simple Perfect swift file caching## Usage
```swift
let cache = PerfectCache()func handler(data: [String:Any]) throws -> RequestHandler {
return { request, response in
response.setHeader(.contentType, value: "application/json")
if cache.return(for: request, with: response) {
return
}// ... Do some stuff to build of the HTTPResponse
cache.write(response: response, for: request)
response.completed()
}
}
let confData = [
"servers": [
[
"name": "localhost",
"port": 8080,
"routes":[
[ "method": "get", "uri": "/user/me", "handler": handler ]
],
"filters": filters()
]
]
]do {
try HTTPServer.launch(configurationData: confData)
} catch {
fatalError("\(error)")
}```