Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
i am trying to make my API service to query my SQL DB every 5 minute, hold his response and share this response with the all next 5 minutes calls.

So, is there a way that i can run the query with timer? and how can i hold the response.
I tried to work with session but i don't know if it is the right way and how exactly to that.
Posted
Updated 7-Dec-15 1:40am
v3

1 solution

Timer is not a possibility inside web application...
What you may do is to store your response on the Application level accompanied with a time stamp...If time stamp is older than the period you want you should reload your response and store it instead of the current, otherwise return the existing one...
C#
if((DateTime.UtcNow - Application["LastQuery"]).TotalSeconds > 300)
{
  Application["Response"] = LoadData();
  Application["LastQuery"] = DateTime.UtcNow;
}

// use Application["Response"] as your answer
 
Share this answer
 
Comments
Tzuriely 7-Dec-15 8:03am    
sorry, but is it "Application" that you used?
Kornfeld Eliyahu Peter 7-Dec-15 8:06am    
Application. Yes. That's something you can share across all of your sessions...
Sergey Alexandrovich Kryukov 7-Dec-15 11:29am    
For a record: a timer is possible, say, on the client side only. In majority of cases, the use of timers is a bad thing; it can be and should be avoided.
—SA

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