开发者

HttpContext.Current.Items is too fast to access item, but How?

开发者 https://www.devze.com 2023-02-11 23:26 出处:网络
I wrote simple test add 100 items to [Collection] read 1000000 times from [Collection] randomly When [Collection]==HttpContext.Current.Items it takes 50 ms

I wrote simple test

  1. add 100 items to [Collection]
  2. read 1000000 times from [Collection] randomly

When

  • [Collection]==HttpContext.Current.Items it takes 50 ms
  • [Collection]==HttpRuntime.Cache it takes 430ms
  • [Collection]==HashTable || [Collection]==Dictionaty 170ms

I guess the overhead of HttpRuntime.Cache is sync

I try to change initial capacity of HashTable/Dictionary? but with no success.

Does anyone know what is the reason of this turbo HttpContext.Current.Items? May I create this kind of object to custom cache implemen开发者_高级运维tation(of course with sync imply).


The reason cache is sluggish is because it is thread safe - as you guessed.

Underlying type for HttpContext.Current.Items is a plain Hashtable. Perhaps if you put a snippet of your code, I would be able to explain the difference with the 3rd item.

0

精彩评论

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