We have a touch screen application that displays events and pictures sent to the app by Web services. There is one particular web service that I have an issue with. It pulls data from the table in SQL for 1 event that user choses on the screen. This particular table has lots of images, around 300 rows, with up to 5 images per row (each image is stored in a different column). Even if I open the table directly in SQL, it takes 18 seconds to load the table with 300 rows. We are working on optimizing images, but not sure how much faster it would be once we are done. Back to the touch screen app. The first call of the web service takes around 25 seconds, I do cache it and all other calls take 2-5 seconds. I tried to set to call the web service at 5 am, pulling the images for the next event, but it didn't solve anything. Still the first call takes 25 seconds. Is there any other way to call the web service in advance, early in the morning? Even that I would always need only 1 event at a time (filter by ID in the service), it seems the first call still takes long time and looks through the whole table. I would not know which event would user press on. Below there is a code for calling the web service
public static List<ActivitiesListViewModel> GetImageOneEvent(bool dontUseCache = false)
{
JavaScriptSerializer ser = new JavaScriptSerializer();
ser.MaxJsonLength = Int32.MaxValue;
MasterListService.MasterLists ms = new MasterListService.MasterLists();
ms.UseDefaultCredentials = true;
string fileCache = CacheFolder + "image.json";
List<MasterListService.ActivitiesListViewModel> ImageInfo = null;
if (HttpRuntime.Cache["imageOneEvent"] != null && !dontUseCache)
{
ImageInfo = HttpRuntime.Cache.Get("imageOneEvent") as List<ActivitiesListViewModel>;
}
else if (File.Exists(fileCache) && !dontUseCache)
{
try
{
ImageInfo = new JavaScriptSerializer().Deserialize<List<ActivitiesListViewModel>>(File.ReadAllText(fileCache));
}
catch (Exception)
{
}
}
if ((ImageInfo == null) || (HttpRuntime.Cache["Act_ID_keep"] != HttpRuntime.Cache["Act_ID"]) || HttpRuntime.Cache["imageOneEvent"] == null)
{
ImageInfo = ms.GetImagesOneActivity(Convert.ToInt32(HttpRuntime.Cache["Act_ID"])).ToList();
HttpRuntime.Cache["Act_ID_keep"] = HttpRuntime.Cache["Act_ID"];
if (ExpCacheImg == null)
{
ExpCacheImg = TimeSpan.FromHours(16);
}
HttpRuntime.Cache.Insert("imageOneEvent", ImageInfo, null, System.Web.Caching.Cache.NoAbsoluteExpiration, ExpCacheImg);
File.WriteAllText(fileCache, ser.Serialize(ImageInfo));
}
return ImageInfo;
}
Aucun commentaire:
Enregistrer un commentaire