开发者

When to cache the results from a web service?

开发者 https://www.devze.com 2023-02-12 12:20 出处:网络
In a section from my web application i get information from http://www.geonames.org/ ( web service method ) and http://data.un.org/ ( xml files stored on our application )

In a section from my web application i get information from http://www.geonames.org/ ( web service method ) and http://data.un.org/ ( xml files stored on our application )

I'm new at this and my questions are:

  1. When to cache the information from geoname开发者_JS百科s ?
  2. What method to use for the cache ?
  3. It will be ok if i cache the xml files or is the same performance ?

I use ASP.NET MVC 2 C#


Caching is a way to improve performance, consider it, only if the current performance is not acceptable, otherwise there is no need to worry.

One way you could cache your data is set up a database table with a CLOB field, a date time of when it was stored and of course fields to identify the object (such as the webservice parameters used to obtain this object).

You've to decide a policy to expire the old objects, for instance you could set up a query to run daily that would delete all objects older than a week. This is an example, I can't tell you for how long to cache, it depends on the size of the data you can keep and on how often it gets updated.

To get to your questions in more detail:

.1. When to cache the information from geonames ?

I'm not sure if I understand correctly, but normally: you'd look up the value in the cache, if it's found you return from the cache, if it's not found you do the service call and you store the result in the cache.

.2. What method to use for the cache ?

I've explained a way with SQL tables, you could also use files, but it's more complicated.

.3. It will be ok if i cache the xml files or is the same performance ?

Whatever you decide to cache, processed or unprocessed (XML) information, it won't change much from a performance point of view, since the biggest delay is fetching the information from the network, not processing it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号