You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 6, 2020. It is now read-only.
extensionKeyedCache{func fetch<T:Codable>(key:String, on worker:Worker, fallback:@escaping()->Future<T>)->Future<T>{returnget(key, as:T.self).flatMap{ cached in
if let cached = cached {return worker.future(cached)}returnfallback().flatMap{self.set(key, to: $0).transform(to: $0)}}}}
Usage
router.get("cached"){ req ->Future<[Cat]>inletcache:KeyedCache=try req.make()return cache.fetch(key:"cats", on: req){Cat.query(on: req).all()// <-- only executed once}}
router.get("cachedOne"){ req ->Future<Cat>inletcache:KeyedCache=try req.make()
guard let name:String= req.query["name"]else{throwAbort(.badRequest)}return cache.fetch(key:"cat-\(name)", on: req){Cat.query(on: req).filter(\Cat.name == name).first().unwrap(or:Abort(.notFound))}}
The text was updated successfully, but these errors were encountered:
Usage
The text was updated successfully, but these errors were encountered: