Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2007

Tip: Looking for answers? Try searching our database.

HttpContext.Current.Cache not working.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
msch-prv@bluewin.ch - 29 Oct 2007 13:36 GMT
    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
bruce barker - 29 Oct 2007 17:03 GMT
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)

>     Hello. I am trying to use caching to populate a datalist. The select
> method of the associated objectdatasource calls up
[quoted text clipped - 38 lines]
>             End If
>         End Function
George Ter-Saakov - 29 Oct 2007 18:32 GMT
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,.

> HttpContext.Current.Cache is only maintained for one request. its mainly
> used for handlers to send data to each other. you want session.
[quoted text clipped - 43 lines]
>>             End If
>>         End Function
marss - 29 Oct 2007 22:50 GMT
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
msch-prv@bluewin.ch - 30 Oct 2007 00:59 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.