Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Manual Refresh of Cached Data

Status
Not open for further replies.

Meleagant

Programmer
Aug 31, 2001
166
US
All,

I have a basic aspx page with a GridView and ObjectDataSource. I have EnableCaching set to true. A user can check a check box in the first column of the GridView, set a status code and update all of the changed records with a button click. After that "update" I want to refresh the dataset. This doesn't seem to be happening. I'm wondering if anyone out there has experience with caching data and then forcing the ObjectDataSource to go back to the Select Method to get new data and not to the cache.

Here's a snippet of what I have (taken from articles that I have found on the web:

ASPX:
Code:
<asp:ObjectDataSource ID="odsProfile" TypeName="GridViewHelper" SelectMethod="GetWorkListData"
runat="server" CacheDuration="0" CacheExpirationPolicy="Absolute" EnableCaching="True">
  <SelectParameters>
     < ... Paramaters .../>
   </SelectParameters>
</asp:ObjectDataSource>

<asp:GridView ID="gvWorkList" runat="server" AutoGenerateColumns="false" AllowSorting="true" ShowHeader="true" Enabled="true" GridLines="Both" UseAccessibleHeader="true" EnableViewState="false" DataSourceID="odsProfile" AllowPaging="true">
   < ... FORMATTING ... />
</asp:GridView>

And the VB page:
Code:
Private Sub Page_Load...
  If IsNothing(Cache(odsProfile.CacheKeyDependency)) Then
    Cache(odsProfile.CacheKeyDependency) = New Object()
  End If
End Sub

'* ** Save Button Event, I want to force the ObjectDataSourceto go back to the Select Method and get new data ** *
Protected Sub wibSave_Click...

  '* ** Exec SQL to Update Checked Rows.
  For Each gv As GridViewRow In gvWorkList.Rows
    ... Do Something ...
  Next

  '* ** Force Refresh.   Does not seem to do anything.
  Cache(odsProfile.CacheKeyDependency) = New Object()
End Sub

Any help would be great

Thanks
-- Joe --

Journeyman -- The Order of the Seekers of Truth and Penitence
 
From VS Help said:
You can set the CacheKeyDependency property to create a dependency between all cache entries that are created by the ObjectDataSource control and the key. You can expire all the cache entries programmatically at any time by expiring the key.
[/quote From VS Help]
 
I thought that "Cache(odsProfile.CacheKeyDependency) = New Object()" did expire the key. At least this is what some of the samples I found instructed. What you are saying is that I am not expiring the key correctly?

Journeyman -- The Order of the Seekers of Truth and Penitence
 
Okay, thanks for the help but I am still a wee bit confused. I tried to add CacheKeyDependency="WorklistCacheKey" to the GridView in the ASPX page.

In the VB Page Load I tried:
Code:
Dim dependencyKey(0) As String
dependencyKey(0) = "WorklistCacheKey"
Dim WorkListDataDependency As New CacheDependency(Nothing, dependencyKey)

Cache.Insert("RefreshKey", "", WorkListDataDependency)

So now later if I change the value of Cache("RefreshKey"), the dependency will trigger the GridView (actually the ObjectDataSource) to re-execute the SQL and refresh the information?


Journeyman -- The Order of the Seekers of Truth and Penitence
 
I belive that is the way it works. I use the cache object independant of the datasources, so it may work a little different than what I am used too.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top