M
msch-prv
Hello. I am trying to use caching to populate a datalist. The select
method of the associated objectdatasource calls up
GetRecipePageByRecipeCatID() to request the proper data (I am using
custom paging at SQL level
so there is a paging idx as well). The code works fine when caching
is edited out.
Problem. The cache object is only created the first time around. When
the dtl ia refreshed, th HttpContext.cache object always returns
nothing. What am I doing wrong (there is no application restart)?
Thks for your input.
Public Function GetRecipePageByRecipeCatID(ByVal RecipeCatID As
Nullable(Of Integer), _
ByVal PageIndex As Nullable(Of Integer), ByVal NumRows As
Nullable(Of Integer), ByRef RecipeCount As Integer) _
As RecipeDataSet.tblRecipesDataTable
' Set key to get/set our cache'd data
Dim strCacheKey As String = "GetRecipePageByRecipeCatID" &
RecipeCatID.ToString() & PageIndex.ToString
If HttpContext.Current.Cache(strCacheKey) IsNot Nothing
Then
Return CType(HttpContext.Current.Cache(strCacheKey),
RecipeDataSet.tblRecipesDataTable)
Else
If Not RecipeCatID.HasValue Then RecipeCatID = 0
If Not PageIndex.HasValue Then PageIndex = 0
If Not NumRows.HasValue Then NumRows = 4 ' Show 4
entries
If IsNothing(RecipeCount) Then RecipeCount = 0
Dim myDataSet As RecipeDataSet.tblRecipesDataTable =
Adapter.GetRecipePageByRecipeCatID(RecipeCatID, PageIndex, NumRows,
RecipeCount)
HttpContext.Current.Cache.Insert(strCacheKey,
myDataSet, Nothing, DateTime.Now.AddMinutes(30), TimeSpan.Zero)
Return myDataSet
End If
End Function
method of the associated objectdatasource calls up
GetRecipePageByRecipeCatID() to request the proper data (I am using
custom paging at SQL level
so there is a paging idx as well). The code works fine when caching
is edited out.
Problem. The cache object is only created the first time around. When
the dtl ia refreshed, th HttpContext.cache object always returns
nothing. What am I doing wrong (there is no application restart)?
Thks for your input.
Public Function GetRecipePageByRecipeCatID(ByVal RecipeCatID As
Nullable(Of Integer), _
ByVal PageIndex As Nullable(Of Integer), ByVal NumRows As
Nullable(Of Integer), ByRef RecipeCount As Integer) _
As RecipeDataSet.tblRecipesDataTable
' Set key to get/set our cache'd data
Dim strCacheKey As String = "GetRecipePageByRecipeCatID" &
RecipeCatID.ToString() & PageIndex.ToString
If HttpContext.Current.Cache(strCacheKey) IsNot Nothing
Then
Return CType(HttpContext.Current.Cache(strCacheKey),
RecipeDataSet.tblRecipesDataTable)
Else
If Not RecipeCatID.HasValue Then RecipeCatID = 0
If Not PageIndex.HasValue Then PageIndex = 0
If Not NumRows.HasValue Then NumRows = 4 ' Show 4
entries
If IsNothing(RecipeCount) Then RecipeCount = 0
Dim myDataSet As RecipeDataSet.tblRecipesDataTable =
Adapter.GetRecipePageByRecipeCatID(RecipeCatID, PageIndex, NumRows,
RecipeCount)
HttpContext.Current.Cache.Insert(strCacheKey,
myDataSet, Nothing, DateTime.Now.AddMinutes(30), TimeSpan.Zero)
Return myDataSet
End If
End Function