开发者

Persist Static Data Through AppPool Recycles

I've created a ASP .Net MVC 3 application that allows users to search through a variety of media files based on their filenames. There are a large number of these files so I've created an inverted index which I store in memory. Specifically, I story it as a

Dictionary<string,List<string>>. 

Well, this index must first be created in order to be searchable, so I created a method to build it. It works fine and everything is great, but naturally every time the AppPool refreshes, my index is lost. I've tried tur开发者_如何学Goning off AppPool recycling, but I'm assuming that's a bad idea (and it seems to recycle regardless).

I'm basically not sure what my next move should be. Is there a way to detect when the AppPool is going to refresh and rebuild my index? Or is it safe to disable app pool recycling altogether?

Cheers, -Josh


Mike's answer is close I think, but not perfect. The issue is that the application start event only fires once when the server itself starts; it does not fire each time the app pool is recycled. I was trying to do this exact thing to serialize some data to disk before the pool recycled and read it back in afterward (in leiu of storing it in a database.) I found that the application start event never fired after the pool recycled so my data was never getting read back in. I could not find an event that does fire after an app pool recycle, so I was forced to read that data back in inside of the constructor of the object that would be holding this data. It works, but leaves the data on the disk longer than I am comfortable with.

It's not an ideal solution in my opinion (even if you encrypt the data as I did), but works none-the-less. Hopefully this helps someone else looking for a similar solution, or maybe someone can stumble upon this and point out an event that actually does fire after the app pool recycles. I'd certainly be interested to find out about that one.


Assuming that the index is available to it, I would have thought you could serialise the index on Application_disposed and then de-serialise it in the application_start event in the global asax?


If you need a persistent key/value store, I would suggest something like Redis. I have had good success using that product in extremely high volume environments (over 500 million transactions in an hour).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜