Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I've winform application where I exposed a WCF service and it is hosted on IIS on the server, and there are around 10 methods in it.

There is some common data that I need in computation of all 10 methods. What I want is to get this common data only once when service start and put it in cache so that all the methods can get the data from this cache instead of getting it from database. Is there any way to achieve it?

What I have tried:

One thing I can do is to check whether there is cache available, is not then fetch it otherwise use existing. But I've to do it in all the exposed methods because I don't know which methods will be called first. So need a clean and short way to do this.
Posted
Updated 27-Nov-16 8:00am

1 solution

I found the simple solution of my this problem. In Cache class I've add a static constructor and there I wrote the code of fetching cache data. As we all know static constructor can be called only once and it can't be called explicitly. So as soon as we try to read any variable of Cache class (all are static variable to hold cache data), our static constructor will be called automatically and it'll fill cache data to respective static variables.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900