locked
Enterprise Library Caching and Sql Dependencies RRS feed

  • Question

  • User672738083 posted

    ok so they didn't add the functionality for the sql dependencies and notifications into the enterprise library, so this is what i came up with so far as a wrapper:

      

            public class SqlExpiration : Microsoft.Practices.EnterpriseLibrary.Caching.ICacheItemExpiration, IDisposable
            {
                private SqlCacheDependency dp = null;
                private string database = string.Empty;
                private string table = string.Empty;
                public SqlExpiration(string database, string table)
                {
                    this.table = table;
                    this.database = database;
    
                    dp = new SqlCacheDependency(database, table);
                }
    
                #region ICacheItemExpiration Members
    
                public bool HasExpired()
                {
                    return dp.HasChanged;
                }
    
                public void Initialize(Microsoft.Practices.EnterpriseLibrary.Caching.CacheItem owningCacheItem)
                {
                }
    
                public void Notify()
                {
                }
    
                #endregion
    
                #region IDisposable Members
    
                public void Dispose()
                {
                    if (dp != null)
                    {
                        dp.Dispose();
                    }
                }
    
                #endregion
            }
     

     am i missing anything? it seems to work fine i just have no idea

    Wednesday, September 27, 2006 5:08 PM

All replies

  • User2006178999 posted

    Hi Harold.NET,

         very interesting indead!!! I like using the EntLibrary Caching service in my custom Data Access Layer instead of the web cache (which all the examples and people say to use) because i feel like it's tightly binding http web stuff to a reusable component (assembly) that might not be doing any web stuff. Pedantic, i know ... but it's the principle, for me at least.

     That said, i stumbled across this post and it has me VERY interested. I'm about to try this out ... but i was curious to see if you ended up using this in any projects? you said 'It seems to work fine' ... but can u elaborte on that - ie. The cache items get wiped/zapped when a database table gets updated -- proving that the sqlnotification broker stuff is working.

    also, did u setup your stuff using the asp_regsql.exe command?

    Please reply - very very intersted :)

    oh, ps. your two database and name fields are redundant - not required.

    Sunday, February 18, 2007 12:22 AM
  • User672738083 posted

    Yes, I used the reqsql command and all.

     

    It is working great for my projects, I see no issues at all with anything.  

    Sunday, February 18, 2007 10:27 AM
  • User2006178999 posted

    Hi Harrold.

    1) Why did u use the aspnet_regsql.exe command? what functionality does it do, which you are required to use?

    2) Why did u go with using the EntLibrary's Caching component instead of using the http caching stuff which most people suggest using? The reason i ask this is because I don't want to use the Asp caching object thing because i'm doing my caching in a Data Access Layer and it seems silly to put web stuff in there when the reusable assembly might not be doing any web stuff at all (eg a winform app) .. even though the System.Web... namespace stuff works fine in a winform ... and the SqlCacheDependency class is found in System.Web.... or something.

    Sunday, February 18, 2007 11:07 PM
  • User-939035837 posted

    Harold,

    Have you used this in a farm/clustered environment?  We ran across a problem with caching in sql server for a couple reasons.  1) I wasn't specifying an expiration so the artifacts remained in cache indefinitely and 2) when a server in the cluster reset, caching would blow chunks until a manual delete was issued for the tables that stored the cached artifacts.

    -T

    Wednesday, October 3, 2007 9:03 AM