Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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)")
}

```