Hi Andrew,
Thank you for posting.
Regarding on the ObjectDataSource's caching behavior , here are some of my
understanding and suggestion:
The objectDataSource control's cache is maintained internally so that we
can not manually view or query through the Page.Cache or HttpContext.Cache
collection. And the cache is created and used during the Select method of
the ObjectDataSource, that means, when ObjectDataSource.Select method is
called, it will check the cache to see whether it should use cache or redo
the query from the underlying data access class. This is different from
the behavior GridView (or other databound control) call
DataSourceControl.Select since DataBound control may store data in
ViewState to avoid querying the datasourcecontrol. In other word, if you
want to test the ObjectDatasource control's cache behavior, you can
manually call ObjectDataSource.Select method and also put some trace
code(like Httpcontext.Current.Response.Write...) in the data access
control's select method to check the behavior.
Also, for the "CacheKeyDependency", when it is set, that means the
ObjectDataSource.Select method will use the cached data only when there is
an existing cache entry in the application Cache and the key of it equals
to the "CacheKeyDependency" property wo set on the ObjectDataSource
control. So we need to add such a cache entry so that the ObjectDataSource
will use the cache, then, when we want to explicitly expire the
ObjectDataSource's cache, just remove that entry(we need to readd it if we
want the objectdatasource to begin using cache again). e.g:
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
CacheDuration="10"
EnableCaching="True" SelectMethod="GetProducts"
TypeName="TestDataObject" CacheKeyDependency="MYKEY">
.................
//test method to manually call ObjectDatasource.Select method
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("<br/>Button1_Click");
ObjectDataSource1.Select();
}
//manually remove the cache entry of the objectdatasource's KeyDependency
protected void btnInvalid_Click(object sender, EventArgs e)
{
Cache.Remove(ObjectDataSource1.CacheKeyDependency) ;
}
// set the key entry
protected void Button2_Click(object sender, EventArgs e)
{
Cache[ObjectDataSource1.CacheKeyDependency] = new object();
}
Hope this helps.
Regards,
Steven Cheng
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)