开发者

How to implement database caching of data from third-party web service?

I'm trying to implement some functionality of caching data from third-party web service into the sql server database.

I开发者_Go百科 have several methods like

  1. IProduct GetProductById(int productId),
  2. IEnumerable<IProduct> ListProductsAllByCategoryId(int categoryId),
  3. IEnumerable<IProduct> ListProductsPagedByCategoryId(int categoryId, int pageNumber, int itemsOnPage, out int totalRowCount),
  4. etc.

So, I have an idea to code/hash method signature + parameters as a Key and serialize output as a Value and store this Key-Value-Pair in the database.

Then I'm planning just to get this items from the database by key.

Question: Is it good idea and how to implement unique key for each combination of (method + parameters)?

Any other solution would be useful for me.


I'm not quite sure what your asking, so I'm going to assume you want to just cache your objects...

The method I've used when I've cached is to have a static guid for each class type (keeps types unique), then I append "-" and the id of the object (which should be unique anyway).

As an alternative to the database have you considered using memcached? - there are .Net versions around and they are very good, just make sure you understand where the right place and what to cache will be, to make sure it is applicable to your scenario.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜