开发者

asp.net webcontrol caching

I'm writing a webcontrol in asp.net which has to go and fetch information from an API. It's not critical to be up-to-date, and retrieving the information is quite slow, so I'd rather cache the information and update it every 5 minutes.

It strikes me as potentially risky to use the Context.Cache as potentially someone could use the same name, but I can't find another way to do caching within a control.

Does anyone开发者_C百科 have any other ideas?

(using asp.net 2.0).


It sounds like the Context.Cache is exactly what you need to store this kind of information. The cache object is localized to your application so it would only be changeable by other code in your application.

You can always give your cache key a very long and presumably useless name etc and store that key within your class...

Private const CacheKey as String = "e92a627b-3a9f-46da-a182-d73b44fe87ad" ' A random guid

Cache.Item(CacheKey) = TheRefreshedData ' etc

As I was writing this answer I realised maybe you were talking about your conntrol being re-used within someone else's application...as in your control is redistributed or provided for download. In this case, you could always prefix the cache key with your control to be "sensibly" unique...

Private const CacheKey As String = "MyCompany.MyControl.MyData" 

Cache.Item(CacheKey) = TheRefreshedData ' etc

Either way, you should be able to come up with some fairly length string that has zero chance of being reused...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜