Static field for members updated; consultation needed

I need advice on the functionality that I have to implement. The scenario is that we have an HttpHandler whose servers intercept file downloads. In the handler, I need to save a large dictionary of strings inside the memory. The dictionary can be up to 100 entries. I am wondering if this can be stored in a static variable so that it does not initialize every time a handler instance is created (there will probably be a lot of instance). In general, what is the approach in such scenarios. Is it better to use static fields to save data that will not be changed?

+3
source share
5 answers

The 100 items in the dictionary are actually not very large - in fact, this hardly comes in size where hashing is faster than a linear search. If it will never change after initialization, then the static one can work - I personally try to get some other abstraction between staticand the instance - for example, the "context" or "configuration" class, which I can go through in all cases that need it. Then I can have several parallel configurations (if necessary), but all instances associated with can share the context / configuration, so duplication is not necessary.

+3
source

IMHO . . , .
, , ...

+1

. (, Global.asax), .

+1

HttpHandler.IsReusable false, . .

.

- 100 - . .

0

, ,

, Readonly

0

Source: https://habr.com/ru/post/1792990/


All Articles