This question is locked. New answers and comments are not allowed.
Hi,
I'm facing an issue that i don't understand.
The scenario is pretty basic, i have a table "FOWineGrappe" that i read and add the List<FOWineGrappe> to a Memory Cache.
ProductManager.GetAllWineGrappes:
and the
I'm facing an issue that i don't understand.
The scenario is pretty basic, i have a table "FOWineGrappe" that i read and add the List<FOWineGrappe> to a Memory Cache.
public
static
string
GetCurrentWineGrappes(FOWine wine)
{
string
grappesStr =
""
;
List<FOWineGrappe> grappes = (from c
in
ProductManager.GetAllWineGrappes()
where c.WineId == wine.WineID
orderby c.Percentage descending
select c).ToList();
if
(grappes.Count > 0)
{
for
(
int
i = 0; i < grappes.Count(); i++)
{
grappesStr += grappes[i].Percentage +
"% "
+ grappes[i].GrappeName +
", "
;
}
grappesStr = grappesStr.Trim().TrimEnd(
','
);
}
return
grappesStr;
}
ProductManager.GetAllWineGrappes:
public
static
List<FOWineGrappe> GetAllWineGrappes()
{
List<FOWineGrappe> wineGrappes = CacheManager.GetItemFromCache(
"Wines_FOWineGrappe"
)
as
List<FOWineGrappe>;
if
(wineGrappes ==
null
)
{
lock
(BuildCacheLock)
{
List<FOWineGrappe> contentsToCache = ProductData.GetAllWineGrappes();
CacheManager.AddItemToMemoryCache(
"Wines_FOWineGrappe"
, contentsToCache);
wineGrappes = CacheManager.GetItemFromCache(
"Wines_FOWineGrappe"
)
as
List<FOWineGrappe>;
}
}
return
wineGrappes;
}
and the
ProducersDate method:
public
static
List<FOWineGrappe> GetAllWineGrappes()
{
List<FOWineGrappe> lst =
new
List<FOWineGrappe>();
try
{
HighLevelFOModel dbContext = GetHighLevelFODBContext();
IQueryable<FOWineGrappe> dcLst = from c
in
dbContext.FOWineGrappes
orderby c.WineId ascending
select c;
return
dcLst.ToList();
}
catch
(Exception ex)
{
LogManager.LogError(
"ProductData"
, MethodBase.GetCurrentMethod().Name, ex);
throw
;
}
}
Now when i profile the application, on the first access to GetCurrentWineGrappes takes just 216ms.
See image A-run1.jpg.
On the 2nd acces it takes 8S! (A-run2.jpg). Note that this time it's all on the cache, not acess to te DB is done.
On 3rd and + access it take only 1ms to get the items from cache. (A-run3.jpg)
I don't understand why run2 takes all that time in the getWineID..
Rafael