It’s been a while since I used Cache in SS, and back then we didn’t have the magic of ToOptimizedResultUsingCache()
, and for such, this is my first steps using it…
I have a simple response:
public Shop Get(GetShop request)
{
return _shopService.GetShop(request.ShopId, request.PortalId);
}
and, by implementing the magic, I will get:
public object Get(GetShop request)
{
var cacheKey = $$"api:shops:GetShop-shop-{request.ShopId}-portal-{request.PortalId}";
return base.Request.ToOptimizedResultUsingCache(
base.Cache,
cacheKey,
() => _shopService.GetShop(request.ShopId, request.PortalId));
}
I can see that ToOptimizedResultUsingCache
accepts a type, like ToOptimizedResultUsingCache<Shop>
but I can’t manage to use it correctly so I can return a Shop
object instead of object
in the call…
Maybe I’m being picky, but is there a way I can still use public Shop Get(GetShop request)
instead have to express object
?
I understand that the object is actually a CompressedResult
type, but… using ToOptimizedResultUsingCache<Shop>
it should cast to a Shop
object right?
P.S.
I’ve tried direct cast as
public Shop Get(GetShop request)
{
var cacheKey = $$"api:shops:GetShop-shop-{(request.ShopId.HasValue ? request.ShopId : 0)}-portal-{(request.PortalId.HasValue ? request.PortalId : 0)}";
return (Shop)base.Request.ToOptimizedResultUsingCache<Shop>(
base.Cache,
cacheKey,
() => _shopService.GetShop(request.ShopId, request.PortalId));
}
but all I got was:
Unable to cast object of type ‘ServiceStack.CompressedResult’ to type ‘…Shop’.