【问题标题】:eBay .NET SDK is causing my Cache and Session to be restartedeBay .NET SDK 导致我的缓存和会话重新启动
【发布时间】:2013-11-13 21:17:19
【问题描述】:

我在使用 eBay .NET SDK (http://go.developer.ebay.com/developers/ebay/documentation-tools/sdks/dotnet) 时遇到各种问题

前几天发了这个问题:

HttpRuntime.Cache doesn't appear to be working

现在经过更多调查,实际上调用 eBay API 似乎正在清除我的 .NET 会话和缓存数据,实际上是重新启动应用程序。

为什么?!!

似乎有问题的功能是我抓取eBay类别的方法。上面的问题首先出现是因为我发现我无法缓存从 eBay 获得的极其缓慢的响应......但是,我似乎可以缓存它,但函数中的某些东西导致应用程序重新启动。

这是我获取类别的方法:

Shared Function DisplayCategories(Optional ParentId As Integer = 0, Optional Level As Integer = 1) As CategoryTypeCollection

    Dim Categories As New CategoryTypeCollection

    Dim apiContext As ApiContext = Credentials.GetApiContext()
    Dim apicall As New GetCategoriesCall(apiContext) With {
        .EnableCompression = True,
        .Site = SiteCodeType.UK,
        .LevelLimit = Level
    }
    If ParentId <> 0 Then _
        apicall.CategoryParent = New StringCollection({"" & ParentId & ""})

    apicall.DetailLevelList.Add(DetailLevelCodeType.ReturnAll)

    'SiteCodeType.UK, New StringCollection({"1"}), 10, False
    Categories = apicall.GetCategories()

    Return Categories

End Function

为简单起见删除了所有缓存代码,但我可以向您保证,运行此函数会清除我的缓存和所有 Session 数据。

知道为什么吗?!!

【问题讨论】:

    标签: .net caching ebay-api ebay-net-sdk


    【解决方案1】:

    我想我现在已经有了解决方案……(两天后答案也很简单)

    原因是 eBay SDK 将其 api 日志文件存储在 bin 文件夹中,该文件在编辑时会导致应用程序重新启动。我将这些代码行添加到 global.asax 中的 application_end

        Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when the application ends
    
        Dim runtime As HttpRuntime = DirectCast(GetType(System.Web.HttpRuntime).InvokeMember("_theRuntime", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.[Static] Or Reflection.BindingFlags.GetField, Nothing, Nothing, Nothing), HttpRuntime)
        Dim shutDownMessage As String = DirectCast(runtime.[GetType]().InvokeMember("_shutDownMessage", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance Or Reflection.BindingFlags.GetField, Nothing, runtime, Nothing), String)
        Dim shutDownStack As String = DirectCast(runtime.[GetType]().InvokeMember("_shutDownStack", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance Or Reflection.BindingFlags.GetField, Nothing, runtime, Nothing), String)
    
    
    End Sub
    

    然后我检查了 shutDownMessage 并返回:

    “关键目录的更改通知。bin dir 更改或目录重命名 HostingEnvironment 启动关闭 HostingEnvironment 导致关闭关键目录的更改通知。bin dir 更改或目录重命名”

    我仔细检查了 bin 文件夹,发现 eBayAPiLog.txt 文件写在那里。

    我现在更改了设置 eBay 日志文件的代码,将其存储在应用程序根目录中。

                'set Api logging
            ApiContext.ApiLogManager = New ApiLogManager
            Dim fileLogger As FileLogger = New FileLogger(String.Concat(AppConfig.SiteRootPath, "eBayAPI_log.txt"), True, True, True)
            ApiContext.ApiLogManager.ApiLoggerList.Add(fileLogger)
    

    通过此更改,应用程序不再回收,会话和缓存仍然存在!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-13
      • 1970-01-01
      相关资源
      最近更新 更多