Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

best way to persist data in .NET Web Service

I have a web service that queries data from this json file, but I don't want the web service to have to access the file every time. I'm thinking that maybe I can store the data somewhere else (maybe in memory) so the web service can just get the data from there the next time it's trying to query the same data. I kinda understand what needs to be done but I'm just not sure how to actually do it. How do we persist data in a web service?

Update: Both suggestions, caching and using static variables, look good. Maybe I should just use both so I can look at one first, and if it's not in there, use the second one, if it's not in there either, then I'll look at the json file.

like image 589
Hertanto Lie Avatar asked Dec 17 '22 10:12

Hertanto Lie


1 Answers

Extending on Ice^^Heat's idea, you might want to think about where you would cache - either cache the contents of the json file in the Application cache like so:

Context.Cache.Insert("foo", _
                 Foo, _
                 Nothing, _
                 DateAdd(DateInterval.Minute, 30, Now()), _
                 System.Web.Caching.Cache.NoSlidingExpiration)

And then generate the results you need from that on every hit. Alternatively you can cache the webservice output on the function definition:

<WebMethod(CacheDuration:=60)> _
Public Function HelloWorld() As String
    Return "Hello World"
End Function

Info gathered from XML Web Service Caching Strategies.

like image 92
Mark Glorie Avatar answered Jan 04 '23 21:01

Mark Glorie