简体   繁体   English

喷涂路由缓存不缓存404

[英]Spray Routing Cache dont cache 404

Hey guys im using the spray routing cache directive with routeCache method to cache my api calls. 大家好,我使用了带有routeCache方法的喷雾路由缓存指令来缓存我的api调用。

But the issue is that if you api is returning 500 for some reason then in that case also spray is caching that and keeps returning 500 until the cache expires. 但是问题是,如果您的api由于某种原因返回500,那么在这种情况下,spray也会进行缓存,并一直返回500,直到缓存过期。

So how can i cache only 200 OK responses in spray cache and not others. 因此,我如何仅在喷雾缓存中缓存200个OK响应,而不在其他缓存中。

Following worked 以下工作

Instead of doing 而不是做

ctx.complete(ErrorCode, Error)

did 做了

ctx.failWith(Error)

Ref: 参考:

(1) https://github.com/spray/spray/blob/master/spray-caching/src/main/scala/spray/caching/LruCache.scala#L79 (1) https://github.com/spray/spray/blob/master/spray-caching/src/main/scala/spray/caching/LruCache.scala#L79

With failWith the value isFailure is set and so cache being done unset 使用failWith值设置了isFailure ,因此未设置完成缓存

(2) http://spray.io/documentation/1.2.2/spray-routing/route-directives/failWith/ (2) http://spray.io/documentation/1.2.2/spray-routing/route-directives/failWith/

To maintain proper status code, can use custom exception handlers as explained in above link 要维护正确的状态代码,可以使用上面的链接中所述的自定义异常处理程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM