0

I am trying to build a system to list items within my Back office system on eBay via the eBay ASP.NET SDK.

Since loading eBay categories isn't terribly fast, and infrequently changing, I figured I'd cache the responses from the requests I'll make.

I have a function which returns a list of eBay categories as an eBay CategoryTypeCollection and I am trying to Cache it, then check for it and retrieve new if necessary:

Dim CategoryList As New CategoryTypeCollection
If HttpRuntime.Cache.Get("eBayCategories") Is Nothing Then
    CategoryList = Categories.DisplayCategories()
    HttpRuntime.Cache.Insert("eBayCategories", CategoryList, Nothing, DateTime.UtcNow.AddMinutes(30), TimeSpan.FromMinutes(0))
Else
    CategoryList = HttpRuntime.Cache.Get("eBayCategories")
End If

However, it is always getting new data.

This is part of a much bigger project, and caching is working for other things, I can't see what I am doing wrong here?

Kevin Panko
  • 8,356
  • 19
  • 50
  • 61
Jamie Hartnoll
  • 7,231
  • 13
  • 58
  • 97

1 Answers1

1

The cache is expiring immediately because you specify 0 minutes to expire.

Change it to Cache.NoSlidingExpiration instead.

HttpRuntime.Cache.Insert("eBayCategories", connectionString, Nothing, DateTime.UtcNow.AddMinutes(30), Cache.NoSlidingExpiration)

See MSDN Cache.Insert.

Kevin Panko
  • 8,356
  • 19
  • 50
  • 61