Suggestion: Add an IHttpCache interface

Last post 12-16-2007 3:19 PM by JeremyS. 5 replies.

Sort Posts:

  • Suggestion: Add an IHttpCache interface

    12-15-2007, 11:18 AM
    • Loading...
    • JeremyS
    • Joined on 10-21-2006, 4:23 AM
    • UK
    • Posts 77

    I think it would be useful if IHttpContext.Cache exposed an IHttpCache interface rather than a concrete Cache object. This would make unit testing code that interacts with the cache much easier.

    Thanks

  • Re: Suggestion: Add an IHttpCache interface

    12-15-2007, 3:38 PM
    • Loading...
    • abombss
    • Joined on 06-27-2006, 4:13 PM
    • Chicago, IL
    • Posts 164

    What are you trying to test and how do you intend to use it? 

    Adam Tybor -- abombss.com
    Filed under: , , ,
  • Re: Suggestion: Add an IHttpCache interface

    12-16-2007, 7:33 AM
    • Loading...
    • JeremyS
    • Joined on 10-21-2006, 4:23 AM
    • UK
    • Posts 77

    I am trying to test an action that stores some data in the HttpContext.Cache. What I would like to be able to do is create a mock Cache object so that I can assert that the correct data has been stored.

    My current solution is to create a wrapper object for the cache. While this works, it would be nice to see it in the framework by default, especially as other properties on httpcontext have been abstracted this way (Reques, Response, Session etc)

  • Re: Suggestion: Add an IHttpCache interface

    12-16-2007, 12:55 PM
    • Loading...
    • abombss
    • Joined on 06-27-2006, 4:13 PM
    • Chicago, IL
    • Posts 164

     Ah, I see +1 to an interface.  Or at least make the default constructor of Cache new up an instance of one of the internal CacheInternal implementations so a simple call to new Cache() can actually be used.

    Adam Tybor -- abombss.com
  • Re: Suggestion: Add an IHttpCache interface

    12-16-2007, 2:27 PM
    Answer
    • Loading...
    • MrKurt
    • Joined on 02-26-2006, 4:46 PM
    • Posts 12
    You can use the cache in a console app (or assembly). I do that for testing purposes, just hit:

    System.Web.HttpRuntime.Cache

    That said, an interface for that would be nice for a lot of reasons.
  • Re: Suggestion: Add an IHttpCache interface

    12-16-2007, 3:19 PM
    • Loading...
    • JeremyS
    • Joined on 10-21-2006, 4:23 AM
    • UK
    • Posts 77

    MrKurt:
    ...just hit: System.Web.HttpRuntime.Cache

    Thanks - I'll use this approach in my tests for now. It seems cleaner than the wrapper object that I was using. The only caveat is having to explicitly remove all items from the cache in my test Setup method.

    An interface would be better though ;)

     

Page 1 of 1 (6 items)
Microsoft Communities
Page view counter