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 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…
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…
Either way, you should be able to come up with some fairly length string that has zero chance of being reused…