如何在 VB.net 中实现 ServiceStack 缓存?我看过很多 C# 示例,但我无法将其转移到 vb.net。
我在第一个和第二个参数中得到堆栈的点ServiceStack.ServiceHost.RequestContextExtensions.ToOptimizedResultUsingCache
- 第一个应该是:
ServiceStack.ServiceHost.IRequestContext
- 不确定 IRequestContext 是什么 - 第二个应该是:
ServiceStack.CacheAccess.Providers.MemoryCacheClient
- 我如何在配置中设置这个做缓存默认值,即 MemoryCacheClient
下面的代码,任何建议都非常感谢。
全球.asax.vb
Public Class Global_asax
Inherits System.Web.HttpApplication
Public Class HelloAppHost
Inherits AppHostBase
Public Sub New()
MyBase.New("Web Services", GetType(Wrapper).Assembly)
End Sub
Public Overrides Sub Configure(ByVal container As Container)
Routes.Add(Of GetProduct)("/GetProduct").Add(Of GetProduct)("/GetProduct/{*}")
Plugins.Add(New Cors.CorsFeature(allowedHeaders:="Content-Type, Authorization"))
container.Register(Of ICacheClient)(New MemoryCacheClient())
End Sub
End Class
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
Dim apphost = New HelloAppHost()
apphost.Init()
End Sub
End Class
WS.vb
Public Class Wrapper
Public Class WrapperGetProduct
Implements IService(Of GetProduct)
Public Function Execute(ByVal request As GetProduct) As Object Implements ServiceStack.ServiceHost.IService(Of GetProduct).Execute
Dim cachekey As String = "some_key"
Dim expireInTimespan = New TimeSpan(1, 0, 0)
Return ServiceStack.ServiceHost.RequestContextExtensions.ToOptimizedResultUsingCache(
ServiceStack.ServiceHost.IRequestContext, // not sure what this should be
ServiceStack.CacheAccess.Providers.MemoryCacheClient, // not sure what this should be - how do I set this to cache setted in configuration (in memory cache)?
cachekey, expireInTimespan,
Function() request.HandleRequest()
)
End Function
End Class
End Class