This is a migrated thread and some comments may be shown as answers.

Caching Data with RadGrid: Good or Bad Practice?

1 Answer 565 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jeremy Yoder
Top achievements
Rank 1
Jeremy Yoder asked on 22 Dec 2009, 05:54 PM

Since I'm not familiar with everything RadGrid and RadWindow can do, I'm wondering if I'm re-inventing the wheel and these controls already do some of this, or something similar.

I have some pretty static data I don't want to query often to save trips. So I thought I'd have the Cache hold the data until 20 minutes after it's no longer requested. (It seems to work, but I've never used the Cache before, so I'm not sure of the pros and cons.) Anyway, I have a RadGrid on an aspx page. Below is the example code behind against the Northwind DB. The aspx page is referenced by a RadWindow that makes it popup modally.

Like I said, I'm wondering if I'm doing more than necessary, or if I'm doing some bad/inefficient coding in regard to your controls, or even in general. Thanks for any input you can give.


Imports System.Data  
 
Partial Class MyRadGrid  
    Inherits System.Web.UI.Page  
 
    Protected Sub RadGrid1_NeedDataSource(ByVal source As ObjectByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource  
 
        Dim strSQL As String 
        strSQL = "SELECT SupplierID, ContactName, City, Region, PostalCode, Country FROM Suppliers" 
 
        Dim strCacheName As String = "SupplierData" 
        Dim ds As DataSet = CType(Cache(strCacheName), DataSet)  
 
        If ds Is Nothing Then 
            Dim aDB As New AccessDataSource("~/App_Data/Northwind.mdb", strSQL)  
            Dim mydv As System.Data.DataView = CType(aDB.Select(DataSourceSelectArguments.Empty), System.Data.DataView)  
            Dim dt As DataTable = mydv.ToTable  
            ds = New DataSet  
            ds.Tables.Add(dt)  
            Cache.Insert(strCacheName, ds, Nothing, Cache.NoAbsoluteExpiration, New System.TimeSpan(0, 0, 20))  
        End If 
 
        RadGrid1.DataSource = ds  
 
    End Sub 
 
End Class 
 

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 24 Dec 2009, 05:42 AM
Hi,

Here are a few links that will  shed some light on caching :
http://demos.telerik.com/aspnet-ajax/grid/examples/client/caching/defaultcs.aspx
http://www.codeproject.com/KB/aspnet/ExploringCaching.aspx

Take a look at them and let me know if it was helpful

Thanks,
Princy




Tags
Grid
Asked by
Jeremy Yoder
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or