1

In my ASP.NET-MVC-application I store information in static classes with static vars. But ASP.NET is recycling all data and threads after and my "App_Start"-procedure will call after the cleanup.

I solved the problem with the backup-tasks with HangFire. But to generate the static-class, I need a long time. The first request after the recycle has to wait while the static-classes are set up.

Why the delay? I am using the EntityFramework and for correct handling I need all records from the database with their relations. So I hold all records with static-classes and use the database as 2nd strategy.

I have no ideas what I can do to improve performance. My first idea was to serialize the complete data - but how is the performance for deserialize a ArrayList with 2K or more records? Is there a way to prevent the recyclefor my static ArrayList?

akop
  • 5,981
  • 6
  • 24
  • 51
  • 4
    2000 records should not take a long time to read from a database. Also, can you explain why you need to keep all the data in memory at all times? This sounds like an anti-pattern but maybe there is some reasoning behind this. – stephen.vakil Aug 31 '16 at 19:31
  • Is your app pool set to AlwaysRunning? – ranieuwe Aug 31 '16 at 19:33
  • I have many relations (lazy loading need very long) and my records are hierarchic I need to rebuild the hierarchy. Yeah, app is set to "AlwaysRunning", but the clean-up clear it. – akop Aug 31 '16 at 19:51

1 Answers1

1

I'd recommend you use the application cache mechanism for ASP.NET instead. However, by default, the cache is still in-memory and maintained within the process, so app pool recycles would still wipe it out. The solution is to change the storage location of the application cache so it's in a different process. See this answer for some recommendations for how to store your application cache.

In short, I wouldn't recommend trying to avoid app pool recycling since it can really save you a lot of trouble.

Community
  • 1
  • 1
Jacob
  • 77,566
  • 24
  • 149
  • 228