Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 CACHE ME PLS

Author  Topic 

OBINNA_EKE
Posting Yak Master

234 Posts

Posted - 2006-07-18 : 04:15:16
What if I add more records to the Author table. how would CACHE know that I have added something, it will still be displaying old data Please explain and code will also help

void Page_Load(Object Src, EventArgs E)
{
DataView Source;
Source = (DataView)Cache["MyDataSet"];
if (Source == null)
{
SqlConnection myConnection = new SqlConnection("server=(local)\\NetSDK;database=pubs;Trusted_Connection=yes");
SqlDataAdapter myCommand = new SqlDataAdapter("select * from Authors", myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "Authors");
Source = new DataView(ds.Tables["Authors"]);
Cache["MyDataSet"] = Source;
CacheMsg.Text = "Dataset created explicitly";
}
else
{
CacheMsg.Text = "Dataset retrieved from cache";
}
MyDataGrid.DataSource=Source;
MyDataGrid.DataBind();
}

dfiala
Posting Yak Master

116 Posts

Posted - 2006-07-18 : 06:42:20
In ASP.NET 2.0 you can use the SqlCacheDependency to invalidate the cache when the underlying data has been updated.

http://msdn2.microsoft.com/en-us/library/system.web.caching.sqlcachedependency.aspx

Dean Fiala
Very Practical Software, Inc
Now with Blogging...
http://www.vpsw.com/blogbaby
Microsoft MVP
Go to Top of Page

OBINNA_EKE
Posting Yak Master

234 Posts

Posted - 2006-07-18 : 07:02:46
I mean in 1.1
Go to Top of Page

dfiala
Posting Yak Master

116 Posts

Posted - 2006-07-19 : 19:58:19
There are work arounds in 1.1, but they are not pretty. You can check this out...

http://msdn.microsoft.com/msdnmag/issues/03/04/wickedcode/

Dean Fiala
Very Practical Software, Inc
Now with Blogging...
http://www.vpsw.com/blogbaby
Microsoft MVP
Go to Top of Page

OBINNA_EKE
Posting Yak Master

234 Posts

Posted - 2006-07-20 : 05:14:36
What if I declare

Source as a Global Variable
Then when doing an Insert or delete, I will set it to null like this
Source = null
Go to Top of Page

dfiala
Posting Yak Master

116 Posts

Posted - 2006-07-20 : 10:22:45
Sure, you could do that, but then you're not using the cache, and not accounting for updates, or outside changes to the database.

Which all could be fine depending on what you're trying to accomplsih.

Dean Fiala
Very Practical Software, Inc
Now with Blogging...
http://www.vpsw.com/blogbaby
Microsoft MVP
Go to Top of Page
   

- Advertisement -