473,387 Members | 1,757 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,387 software developers and data experts.

ObjectDataSource caching questions

Hi

I've implemented caching for my ObjectDataSource.

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
EnableCaching="True" CacheDuration="10" CacheExpirationPolicy="Sliding"

SelectMethod="GetUsers" TypeName="BizObject"></asp:ObjectDataSource>

This works, however I need to explicitly clear/remove the cache when I
delete record(s). (It's a custom delete, not a ObjectDataSource builtin
one.) I understand that I need to set the CacheKeyDependency property so
that I can Remove it from the cache?

When I add this line to the above the cache stops working, i.e. the
SelectMethod retrieves the data from the database each time.

CacheKeyDependency="GVkey"

Can someone point me in the right direction? How do I see what's in the
cache? If I write this out it is always zero even when the cache is working.

Literal1.Text = "The number of items in the cache:" +
Cache.Count.ToString();

Very confused. Thanks
Andrew
Apr 10 '06 #1
2 6243
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.)
Apr 11 '06 #2
Hi,

this is from a post about the ObjectDataSource:

"Sometimes we may need to invalidate the cached data for the
ObjectDataSource. To do so we can use the CacheKeyDependency property.
When the control caches the data returned from the SelectMethod, it
will check the value of CacheKeyDependency, and if it's set the
cached data will have a dependency on that cache key. When we want to
remove the cached data we can use the Cache.Remove method using the key
specified in the CacheKeyDependency".

If you want to check the full post:

http://www.manuelabadia.com/blog/Per...2f72d0c86.aspx

The ObjectDataSource uses the internal cache to store data. To view the
cached data you can use Nikhil's web development helper or Cristian
Civera's ViewState Analyzer.

Hope it helps,

Manu

J055 ha escrito:
Hi

I've implemented caching for my ObjectDataSource.

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
EnableCaching="True" CacheDuration="10" CacheExpirationPolicy="Sliding"

SelectMethod="GetUsers" TypeName="BizObject"></asp:ObjectDataSource>

This works, however I need to explicitly clear/remove the cache when I
delete record(s). (It's a custom delete, not a ObjectDataSource builtin
one.) I understand that I need to set the CacheKeyDependency property so
that I can Remove it from the cache?

When I add this line to the above the cache stops working, i.e. the
SelectMethod retrieves the data from the database each time.

CacheKeyDependency="GVkey"

Can someone point me in the right direction? How do I see what's in the
cache? If I write this out it is always zero even when the cache is working.

Literal1.Text = "The number of items in the cache:" +
Cache.Count.ToString();

Very confused. Thanks
Andrew


Apr 12 '06 #3

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

Similar topics

3
by: Oldman | last post by:
Is there a way to manually expire the cache for an objectdatasource?
0
by: osh | last post by:
Fellow ASP.net'ers... I am working on a solution that needs to perform a search (search criteria can be as little as 1 and as high as 20 fields) through an average of 25,000 records and return...
1
by: Felix_WafyTech | last post by:
Hi, I'm working with the ObjectDatasource and the application is getting more and more chatty. Is there a way I could make the ObjectDatasource support multiple DataTables that could be...
7
by: M C | last post by:
Hi, This is a problem that has been haunting me for days and I've come to a complete dead-end. I'm using a objectdatasource to select and update a gridview control. Populating with select works...
10
by: J055 | last post by:
Hi I've been trying out SqlCacheDependency using the ObjectDataSource and SQL Server 2005. It all works quite well with the minimum of configuration, e.g. <asp:ObjectDataSource...
3
by: Doug Salomon | last post by:
Hi, Recently, my site has been generating errors which say: "Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled...
2
by: Jami Bradley | last post by:
I'm in need of some design suggestions! We have a fairly large DB with thousands of users accessing data throughout the day. I have been given the task of restructuring a core part of the web...
1
by: Barry L. Camp | last post by:
Hi all, Wondering if someone can help with a nagging problem I am having using a GridView and an ObjectDataSource. I have a simple situation where I am trying to delete a row from a table, but...
5
by: Randy Smith | last post by:
Hi ALL, I wonder if anyone has been using n-tier to bind to a GridView control by using the ObjectDataSource. This is our first OOP web application, and we have no tables. Right now we are...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.