Skip to content

.Net Cache Datatable with CacheDependency

February 10, 2012
      Shared Function TestData(Optional ByVal refresh As Boolean = False) As DataTable
            OpenIssues = DirectCast(HttpRuntime.Cache("TestData"), DataTable)
            If TestData Is Nothing Or refresh Then
                Dim sql As New System.Text.StringBuilder
                sql.Append("SELECT  Field1, Field2, Field3, Field4  ")
                sql.Append("FROM   dbo.TestData ")
                sql.Append("ORDER  BY Field1 ")
                Using cn As New SqlConnection(Conn)
                    Using cmd As New SqlCommand(sql.ToString, cn)
                        Using dep As New SqlCacheDependency(cmd)
                            TestData= New DataTable
                            HttpRuntime.Cache.Insert("TestData", TestData, dep, Cache.NoAbsoluteExpiration, TimeSpan.FromHours(24))
                        End Using
                    End Using
                End Using
            End If
        End Function

From → .Net, CodeProject

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: