Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > SQLCacheDependency not working - Cache item is always null

Reply
Thread Tools

SQLCacheDependency not working - Cache item is always null

 
 
mark4asp
Guest
Posts: n/a
 
      08-07-2007
Help: SQLCacheDependency not working. When I step through my code
with the debugger I notice that the condition below:

(cacheItem == null)

is always true.

I have setup SQLCacheDependency to work with 11 tables in the
database. When I update the database without actually changing the
"PensionFund" table then I notice that the Cache is being invalidated
anyway. This is not the behavior I want. I only want the Cache to be
invalidated when I alter the PensionFund table.

data_list class:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Caching;
using System.Web.Security;
using System.Data.SqlClient;
using System.Text;
using System.Collections.Generic;

public class data_list
{
public static List<PensionFund> GetPensionFunds(out bool changed)
{
changed = false;
string cacheName = "PensionFund";
List<PensionFund> cacheItem = HttpRuntime.Cache[cacheName] as
List<PensionFund>;
if (cacheItem == null)
{
changed = true;
cacheItem = GetPensionFunds_FromDataSource();
SqlCacheDependency dep = new SqlCacheDependency("Admin",
cacheName);
HttpRuntime.Cache.Insert(cacheName, cacheItem, dep);
}
return cacheItem;
}

private static List<PensionFund> GetPensionFunds_FromDataSource()
{
List<PensionFund> pensionFunds = new List<PensionFund>();
using (SqlConnection dConn = new
SqlConnection(data_connection.SqlConnectionString) )
{
using (SqlCommand cmd = new
SqlCommand("PensionFund_Get_All_For_Listing", dConn))
{
cmd.CommandType = CommandType.StoredProcedure;
try
{
dConn.Open();
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
PensionFund pensionFund = new PensionFund
(
(int)reader["PensionFundID"],
reader["FundName"].ToString()
);
pensionFunds.Add(pensionFund);
}
}
}
catch (Exception e)
{ pensionFunds = null; }
}
}
return pensionFunds;
}
}


web.config entries:

<connectionStrings>
<add name="myDBConnString_localdev" connectionString="Data Source=.
\SQLEXPRESS;Integrated Security=True;Initial Catalog=myDB_40;Min Pool
Size=5;" providerName="System.Data.SqlClient"/>
</connectionStrings>

<system.web>
<caching>
<sqlCacheDependency enabled="true" pollTime="1000">
<databases>
<add name="Admin"
connectionStringName="myDBConnString_localdev" pollTime="1000" />
</databases>
</sqlCacheDependency>
</caching>
</system.web>

 
Reply With Quote
 
 
 
 
mark4asp
Guest
Posts: n/a
 
      08-07-2007
OK, My fault. Sorry for bothering y'all. I noticed that although the
content of data in the PensionFund table is NOT altered it is actually
changed each time because the PensionFund table is either INSERTed
into or UPDATEd. Hence the SQLCacheDependency is rightly flagging a
change. Ideally I need to record whether the PensionFund table data
changes so that, then and only then will I need to UPDATE it.

On 7 Aug, 15:49, mark4asp <mark4...@gmail.com> wrote:
> Help: SQLCacheDependency not working.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't get SqlCacheDependency working correctly Joel Barsotti ASP .Net 7 12-21-2009 12:56 PM
'The SQL Site Map Provider and SQLCacheDependency not working Anton ASP .Net 0 03-12-2007 09:27 AM
SqlCacheDependency - Cache Invalidation wihout result set modification mrashidsaleem@hotmail.com ASP .Net 2 01-10-2007 07:24 AM
How Cache gets updated using SqlCacheDependency Jayender ASP .Net 0 08-30-2006 11:36 AM
"stringObj == null" vs "stringObj.equals(null)", for null check?? qazmlp1209@rediffmail.com Java 5 03-29-2006 10:37 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57