SqlCacheDependency with CacheItemUpdateCallback throws exception
<p>I've been implementing an SqlCacheDependency with a CacheItemUpdateCallback but can't quite get it working the way it should...</p>

<pre><code>private SqlCacheDependency SalesSqlCacheDependency = null;
private List&lt;Sale.Library.Sales.Sale&gt; Sales
{
    get
    {
        if (HttpContext.Current.Cache["Sales"] == null)
        {
            using (SqlConnection Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["SaleConnectionString"].ConnectionString))
            {
                using (SqlCommand Command = new SqlCommand("dbo.usp_GetSales", Connection))
                {
                    Command.CommandType = CommandType.StoredProcedure;
                    SalesSqlCacheDependency = new SqlCacheDependency(Command);
                    try
                    {
                        Connection.Open();
                        Command.ExecuteNonQuery();
                    }
                    catch (SqlException ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        Connection.Close();
                    }
                }
            }
            HttpContext.Current.Cache.Insert("Sales", GetActiveSales(), SalesSqlCacheDependency, DateTime.Now.AddMinutes(1), Cache.NoSlidingExpiration, new CacheItemUpdateCallback(SalesCacheItemUpdateCallback));
        }
        return HttpContext.Current.Cache["Sales"] as List&lt;Sale.Library.Sales.Sale&gt;;
    }
}

private void SalesCacheItemUpdateCallback(string key, CacheItemUpdateReason reason, out object expensiveObject, out CacheDependency dependency, out DateTime absoluteExpiration, out TimeSpan slidingExpiration)
{
    //dependency = SalesSqlCacheDependency;
    absoluteExpiration = DateTime.Now.AddMinutes(1);
    slidingExpiration = Cache.NoSlidingExpiration;
    expensiveObject = GetActiveSales();
}

private List&lt;Sale.Library.Sales.Sale&gt; GetActiveSales()
{
    List&lt;Sale.Library.Sales.Sale&gt; sales = new List&lt;Library.Sales.Sale&gt;();
    //Execute SP and load to sales object
    return sales
}
</code></pre>

<p>Unfortunately this code continually throws this exception:</p>

<blockquote>
  <p>System.InvalidOperationException     Exception message: An attempt was made to reference a CacheDependency object from more than one Cache entry.</p>
</blockquote>

<p>Now I do know why this is happening. Once the cache is expired or the dependency changes, the item update callback delegate is invoked which attempts to assign SalesSqlCacheDependency to the out dependency parameter of the SalesCacheItemUpdateCallback method. However, what I can't figure out is how to stop this from happening whilst retaining the CacheDependency and CacheItemUpdateCallback as if you set (out) dependency to null, the dependency is lost from that point forward.</p>

<p>So..... what am I doing wrong and how is the best way to implement this type of caching?</p>

<p>A couple of things:</p>

<ul>
<li>Please don't comment on the absolute expiry time; that's for debugging purposes only and will of course not be set to 1 minute in a live environment.</li>
<li>The processing within the GetActiveSales() method is VERY complicated and therefore I do not want to have any duplication of it.</li>
</ul>

<p>All help as always is greatly appreciated!</p>
