1
在我看到的所有示例like this中,ServiceStack方法中的緩存必須具有返回類型System.Object。是否有更新的/更新的文檔可以返回正常的DTO?使用ServiceStack + Redis進行緩存:如何不返回System.Object並返回DTO?
例如,如果此Get方法沒有返回「對象」(從ServiceStack文檔中提取),那將會更好。
public class OrdersService : Service
{
public object Get(CachedOrders request)
{
var cacheKey = "unique_key_for_this_request";
return base.RequestContext.ToOptimizedResultUsingCache(base.Cache,cacheKey,()=>
{
//Delegate is executed if item doesn't exist in cache
//Any response DTO returned here will be cached automatically
});
}
}
在這一點上返回DTO有什麼好處? –
它會更加明確一些,並且與其他服務方法返回具體類型一致。 – mariocatch
公平 - 我並不認爲這是值得的,因爲返回類型由您的CachedOrders類型實現的IReturn <>接口指定。保持它作爲一個對象在其他方面提供了更大的靈活性,例如,如果你想返回一個HttpError。 –