How should i be using Booksleeve with protobuf-net?

自作多情 提交于 2019-11-28 09:31:48
Marc Gravell

That is entirely correct. "Get" (BookSleeve) returns a deferred byte[]. You have correctly used Wait to get the actual byte[], then used a MemoryStream over this byte[] to call Deserialize via protobuf-net.

All good.

If you make it clear any steps that you find ugly, I might be able to be more specific, but:

  • BookSleeve is entirely async via Task, hence the need for either Wait or ContinueWith to access the byte[]
  • protobuf-net is entirely Stream-based, hence the need for MemoryStream to sit on top of a byte[]

Of course, if you add a generic utility method (maybe an extension method) you only need to write it once.

And with the addition if a wrapper class (for some tracking/sliding-expiry) and a L1 cache (Redis as L2), this is pretty much exacty how we use it at stackoverflow.

One note: the connection is thread safe and intended to be massively shared; don't do a connection per operation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!