Skip to content

Commit

Permalink
cachear las respuestas del pedidos de recursos
Browse files Browse the repository at this point in the history
  • Loading branch information
nnydjesus committed May 2, 2016
1 parent d63676c commit 146442e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ class ProductController extends ResourceController[Product, ProductDTO]{
class PriceController extends ResourceController[Price, PriceDTO]{
override val service = new PriceService

get("/found-prices"){ request: ListRequest =>
response.ok.json((cacheService.memorize("prices"){service.all(request.limit, request.offset)}))
}
get("/found-prices")(all)

post("/found-prices")(save("found-prices"))
post("/found-prices/:id")(byId)
Expand All @@ -42,7 +40,7 @@ class ShopController extends ResourceController[Shop, ShopDTO]{
override val service = new ShopService

get("/shops"){ request: ShopRequest =>
response.ok.json(service.search(request))
response.ok.json(cache(request){service.search(request)})
}

get("/shops/:id")(byId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ abstract class ResourceController[T <: Resource, D <:DTO[T]](implicit manifestT:
val service = new ResourceService[T, D]{}
lazy val cacheService = new CacheService

def cache(request:Any) = cacheService.memorize(request.toString)_

def all = { request: ListRequest =>
response.ok.json(service.all(request.limit, request.offset))
val result = cache(request){service.all(request.limit, request.offset)}
response.ok.json(result)
}

def save(endpoint:String) = { dto: D =>
Expand Down

0 comments on commit 146442e

Please sign in to comment.