ASP.Net Caching

前端 未结 5 1866
再見小時候
再見小時候 2021-01-23 01:41

I\'ve got an application that downloads data from a 3rd party at 3am every morning Nothing changes in terms of content until then...

is it possible to cache the \"produc

5条回答
  •  死守一世寂寞
    2021-01-23 02:10

    Another option is to use the System.Web.Caching.Cache class. Each time you load your data you can cache it here and then retrieve it as needed. This class does allow for expiration by TimeSpan but since you download the data at a specific time each day that doesn't really matter.

    using System.Web.Caching;
    Public Class SomeClass
    {
      Public SomeDataCollection GetCachedData()
      {
          if( Cache["Key"] == null) //You want to always be sure to check if set
             Cache["Key"] = GetDataCollectionFromSomewhere();
    
          return Cache["Key"];
      }
    }
    

提交回复
热议问题