How could I load data when the service start? As of now I host my service at console app, before my service start I load first all the information from my database into the memory
( other object hold all the information before my service ). I’m using static variable to access the data inside my sevice. I know this approach is wrong, how could I make it right. I’m using nettcp binding and it is self-hosted. Thank you in advance! 🙂
How could I load data when the service start? As of now I host
Share
Why do you think this approach is wrong? If your data does not change at all, static variable works just fine. If you data changes but not very frequently and your application can survive with somewhat “stale” data, you can use System.Web.Caching.Cache and automatically expire data from cache based on time or other dependencies.
If you don’t ever want to burden your service users from waiting while your application is retrieving data from the database, you would either have to have a separate thread that monitors your database and updates cached values or use SqlCacheDependency mechanism to invalidate and refresh your cache values when underlying data changes in the database.