0

I'm working on a WebApplication, and I need to implement a cache mechanism. Basically I need to call a Webservice and update the cache with the results.

My first attempt was to do that with a timer. Created the class with methods to initialize the timer, the timer then calls the webservice and updates de cache. Then I simply call my class in the Application_Start.

The problem is that the webservice invoke is implemented in a utils class, and it needs HttpContext.Current, wich is always null. This is because the method of that utils class is called by the timer, wich basically does not have HttpContext.

After searching a lot of solutions I've tried with ExecutionContext and SynchronizationContext, but that does not seem to work either (or maybe I don't know how to use it), because they are always null.

So, what should I do?

  • Without discussing about your cache mechanism: fake it (HttpContext) in the same way you would do to set up a test for that class (example [here on SO](http://stackoverflow.com/questions/4379450/mock-httpcontext-current-in-test-init-method)). – Adriano Repetti Jun 19 '13 at 15:58
  • Possible duplicate [Caching in C#/.Net](http://stackoverflow.com/questions/1276569/caching-in-c-net) – Dustin Kingen Jun 19 '13 at 15:59
  • After much reading, now I know that in IIS7.0 the Request object from HttpContext.Current (wich is used to call th webservice) is no longer available when the Application_Start event is fired. So I'll have to find another solution. – Vitor Gonçalves Jun 20 '13 at 15:37

0 Answers0