I'm trying to make a request every 10 seconds to a webApi controller in ASP.NET. The controller has to check in the database (SQL Server) if there are new data available (Using enitity framework). Here is the controller side
public class RemoteCommandController : ApiController
{
public Command Get(String id)
{
Command command = null;
ProxyCommand proxycommand = null;
Device deviceSearch;
using (var systemDB = new DB())
{
deviceSearch = systemDB.Devices.Include("CommandList").Where(d => d.Name.Equals(id)).SingleOrDefault();
command = deviceSearch.CommandList.LastOrDefault();
}
if (command.IsExecuted == false)
{
proxycommand = ConvertingObjects.FromCommandToProxy(command);
}
return proxycommand;
}
}
I want to avoid to query the DB everytime I call this controller. Is there a way to improve this controller in order to reduce the number of querys? I was thinking of using Session, but I don't think is a good idea...