Developer forum

Forum » Development » HttpContext in an IndexBuilderExtender

HttpContext in an IndexBuilderExtender

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi there,

In an attempt to optimize code in an IndexBuilderExtender, I wanted to preload some data and store it in HttpContext.Current.Items so I have it available for subsequent calls to ExtendDocument. However, HttpContext.Current is null (and so is the Dynamicweb context). Just curious why that is. Is it running on a separate thread?

Imar


Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Imar,

Yes, it's running on a background thread.

You should be able to have a ThreadStatic property where you store your data, as we don't shift threads like a request could do, and we also don't reuse threads. I have not tested it, but I don't see any issues with that.

- Jeppe

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Thanks Jeppe. The problem with ThreadStatic (or any other static property) is that it survives multiple invocations of the index builder. As far as I know, only one instance of my IndexBuilderExtender is created per application lifetime and then that instance is reused for all index builds. This then means I have data laying around after each build instead of having it disappear automatically like it would with HttpContext.

I think caching with a relatively short expiration time is the way to go.

Thanks!

Imar   

 

You must be logged in to post in the forum