473,322 Members | 1,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

HttpContext.Current.Cache not working.

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

Oct 29 '07 #1
4 11772
HttpContext.Current.Cache is only maintained for one request. its mainly
used for handlers to send data to each other. you want session.
-- bruce (sqlwork.com)

ms******@bluewin.ch wrote:
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
Oct 29 '07 #2
I think you are mistaken
HttpContext.Current.Cache is the same as Application.Cache and lives as
Application.
HttpContext.Current.Items is the one that lives only during that request's
lifetime....

George,.


"bruce barker" <no****@nospam.comwrote in message
news:un**************@TK2MSFTNGP02.phx.gbl...
HttpContext.Current.Cache is only maintained for one request. its mainly
used for handlers to send data to each other. you want session.
-- bruce (sqlwork.com)

ms******@bluewin.ch wrote:
>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

Oct 29 '07 #3
On 29 , 14:36, msch-...@bluewin.ch wrote:
HttpContext.Current.Cache.Insert(strCacheKey,
myDataSet, Nothing, DateTime.Now.AddMinutes(30), TimeSpan.Zero)

This problem may be caused by contradiction between the absolute and
the sliding expiration.

Try this:

HttpContext.Current.Cache.Insert(strCacheKey, myDataSet, Nothing,
DateTime.Now.AddMinutes(30),
System.Web.Caching.Cache.NoSlidingExpiration)

or this:

HttpContext.Current.Cache.Insert(strCacheKey, myDataSet, Nothing,
System.Web.Caching.Cache.NoAbsoluteExpiration, new
TimeSpan(0,30,0))
Regards,
Mykola
http://marss.co.ua

Oct 29 '07 #4
Thanks for your replies.

I was able to solve the problem after I realized that the the system
was short on RAM (my system is limited to 770 MB RAM). So closing a
bunch of FireFox pages solved the issue. Caching works ok.

A nasty side-effect has however now creeped in: the
odsRecipeDet_Selected event of the datalist's associated
ObjectDataSource (odsRecipeDet) which is automatically triggered for
"fresh" data does not fire for cached data. This event is used to
update the custom navigation hyperlinks of the datalist. How can I re-
enable this event for cached data?

Thanks again for any hints.

Oct 30 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: George Ter-Saakov | last post by:
What is HttpContext.Cache for ? The usual HttpRequest lasts miliseconds. Why would someone to cache anything? We do have HttpContext.Items to keep any extra info during the request. Can...
5
by: DesignerX | last post by:
What is the difference between Page.Cache and HttpContext.Current.Cache? Do these access the same thing? Is there any easy way to clear all items in the cache? TIA, Stan
4
by: Mat | last post by:
Hi, I've stumbled onto a problem when using the caching object in ASP.Net. I'm placing a static dataset to the cache as the data only changes once a day. Whilst writing to the cache I'm using...
3
by: xzzy | last post by:
A. I need to access: System.Web.HttpContext.Current.Cache but get this error: "Object reference not set to an instance of the object" B. System.Web.HttpContext.Current.Cache is accessible...
1
by: Graham | last post by:
Here is the problem: In Application_Start() I am setting the cache thus: HttpContext.Current.Cache = myObj; In a subsequent page request, I am accessing the cache thus: MyObj myObj =...
0
by: =?Utf-8?B?TWFydGlu?= | last post by:
Hi I have a component (vb.net class project) which is used by both a web app and windows app. But it uses Web.HttpContext.Current.Cache , works fine in the web app but refuses to work in the...
6
by: =?Utf-8?B?emlubw==?= | last post by:
in asp.net 2, I load a dataset from the Cache object into a local object to use to perform processing. I had been using httpcontext.current.cache and what I noticed is sometime I'm not able to get...
3
by: Madhur | last post by:
Hello I am delivering an asp.net 2.0 application to my customer. I need to know, If I need to check for the condition of HttpContext.Current to be null in my business logic. I have extensively...
8
by: SpaceMarine | last post by:
hello, my web app form has many DropDownLists that pull their content from a database. these calls are in a Business Access Layer, when first checks the context's Cache object for existing...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.