7

I'm using HttpContext.Current.Items to make a Per-Request Cache Store. I'm experiencing strange problems because I'm hitting to many Cache entries over different http requests.

It seems that HttpContext.Current.Items is reused across multiple http requests. Is it normal?

Ricibald
  • 9,369
  • 7
  • 47
  • 62

2 Answers2

6

It was my fault. I was saving HttpContext.Current.Items in a static variable...

Ricibald
  • 9,369
  • 7
  • 47
  • 62
  • 1
    Yeah, don't do that. That's the #1 reason people run into this issue. :) – Haacked Jan 27 '11 at 19:11
  • And avoid any other stuff that might not cause the objects to go out of scope per request, such as putting request cache objects also into Session state, etc. – Shan Plourde Jan 27 '11 at 19:17
2

HttpContext.Current.Items is supposed to be scoped on a per HTTP request. Have you confirmed on subsequent HTTP requests that there still are the same number of Items cached? Perhaps by checking the Items count before any code populates it?

Shan Plourde
  • 8,528
  • 2
  • 29
  • 42