小编jen*_*ens的帖子

在升级到喷雾1.2后,喷射Marshaller的期货不在隐含范围内

在更新到喷雾1.2后,我遇到了一个与我的JSON-Marshallers完全兼容的问题.在HttpService中执行以下操作

trait TestHttpService extends HttpService with SprayJsonSupport with DefaultJsonProtocol{ self : ActorLogging =>
    case class Test(hallo: String, test: String)
    implicit val storyJsonFormat = jsonFormat2(Test.apply)

    def test(implicit m : Marshaller[Future[Test]]) = 17
    def hallo = test 
}
Run Code Online (Sandbox Code Playgroud)

导致以下错误:

could not find implicit value for parameter marshaller:
spray.httpx.marshalling.Marshaller[scala.concurrent.Future[amanuensis.story.Story]]
Run Code Online (Sandbox Code Playgroud)

当我删除未来时,一切运作良好:

trait TestHttpService extends HttpService with SprayJsonSupport with DefaultJsonProtocol { self : ActorLogging =>
    case class Test(hallo: String, test: String)
    implicit val storyJsonFormat = jsonFormat2(Test.apply)

    def test(implicit m : Marshaller[Test]) = 17
    def hallo …
Run Code Online (Sandbox Code Playgroud)

scala future akka spray

9
推荐指数
1
解决办法
2463
查看次数

spray-cache:仅在不是None时缓存

我有一个db-access我想缓存在我的akka​​/spray-application中.db返回Future [Option [X]].

我设置了一个lruCache并将其包装在我的db-access中.

我想要实现的是,仅缓存Option,如果它是Some(X)而不是,如果它是None.在后一种情况下,应再次从数据库中检索数据.

如果这会有所帮助,我可能会在未来失败......

到目前为止,我通过map再次从缓存中删除Option,如果它是None或者将来失败,则恢复:

cache(key) {
      server.one[X](...)
}.map {
   case Some(x) => Some(x)
   case None => {
     cache.remove(key)
     None
  }
}.recover {
  case x => userCache.remove(key)
}
Run Code Online (Sandbox Code Playgroud)

但这非常难看,更不用说地图中的副作用等等......

先感谢您,

caching scala spray

2
推荐指数
1
解决办法
624
查看次数

标签 统计

scala ×2

spray ×2

akka ×1

caching ×1

future ×1