I am trying to populate dropdowns using a generic funtion that sits in my data layer component when i try and compiling the code (see below) using vbc it generates the following error cache not declared... here is the batch file i used to perfom the compiling
---- t indir=c:\vb\db.vb set outdir=c:\bin\db.dll set assemblies=System.dll,System.Data.dll,System.Web.dll,System.Xml.dll vbc /t:library /out:%outdir% %indir% /r:%assemblies% ---- below is the function I want to integrate in my component ---- Imports system
Imports system.web.caching Imports system.Configuration Imports system.Data Imports system.Data.sqlClient Imports system.xml Namespace db ' ' some other function here ' ' PUBLIC Function GetCachedData(ByVal table As String) As DataView Dim ds As DataSet Dim
adpt As SqlDataAdapter Dim conn As SqlConnection Dim cmd As SqlCommand If Cache("haiku." & table) Is Nothing Then conn = New SqlConnection(ConfigurationSettings.AppSettings("key_connectionString")) cmd = New SqlCommand("Get" & table, conn) cmd.CommandType
= CommandType.StoredProcedure adpt = New SqlDataAdapter(cmd) ds = New DataSet() adpt.Fill(ds, table) Cache.Insert("haiku." & table, ds.Tables(table), _ Nothing, DateTime.MaxValue, _ TimeSpan.FromMinutes(1)) End If Return CType(Cache("haiku." & table), DataTable).DefaultView
End Function End Class End Namespace ---- What am I doing wrong? Is it a good idea to access the cache from business / data layer ? thanking you in advance for your insight b
:: Is it a good idea to access the cache from business / data layer ? I do it... any reason why not to do it? In fact, I use a very simular data layer as you do... but I am going to change mine
because I want to use ADO.NET to the full advantage of strongly typed datasets by not using a database system (SqlClient, OleDb, ect.)
You can also access the cache via the following: Cache cache System.Web.HttpRuntime.Cache; The advantage of this method is that it works even on a thread that is not processing a request. Adam
This posting is provided "AS IS" with no warranties, and confers no rights.
benoyt
Member
5 Points
1 Post
encapsulating caching in data layer
Jul 26, 2003 12:19 AM|LINK
jlovell
Member
670 Points
134 Posts
Re: encapsulating caching in data layer
Jul 26, 2003 04:13 PM|LINK
Adam Smith
Member
90 Points
18 Posts
Microsoft
Re: encapsulating caching in data layer
Aug 01, 2003 06:23 PM|LINK
jlovell
Member
670 Points
134 Posts
Re: encapsulating caching in data layer
Aug 01, 2003 08:18 PM|LINK