具体问题如下:
环境:ASP.NET 2.0+ACCESS
数据库中的BlogConfig表中有以下字段:blogName,blogUrl,blogNotice,serachKey等..
现在要将些字段绑定至某ascx usercontrol中的控件上...
要求:1\后台设置一旦改变这些字段的值前台值应立即改变,我该用哪一种缓存方式,(如果不采用缓存方式,调用首页要来来回回查询数据库调用六七次,严重影响性能).
2\在代码上如何实现 //我对缓存似乎还是一知半解?
3\API缓存是可以建立对access数据库中表的依赖?

解决方案 »

  1.   

    据我所知,.net中的缓存自动更新,一般有以下几种方式:
    1,设计缓存依赖或过期。 此时缓存会失效,并生建
    2,自己用一些方式来实现缓存失效并重建
    3,第三方的一些工具,比如cache server
    1,缓存依赖和过期
    可以设置为
    a,文件依赖: 当个依赖的文件变更时,缓存被更新
    b,健值依赖: 当某个依赖于另一个cache项的cache的依赖项变更时,它被变更。 即 cache["a"]依赖于cache["b"],当b变更时,a也失效。
    c,过期: cache.insert方法中指定过期时间
    d,数据库依赖:参见
    http://msdn2.microsoft.com/zh-cn/library/ms178604(VS.80).aspx2,比如我用触发器在数据变更时去触发执行重建缓存的方法3,比如Memcached.
      

  2.   

    access不支持基于通知的缓存依赖,你只能使用基于时间过期的缓寸.
    或者用SqlServer2005
      

  3.   

    你好,我也曾经碰到过缓存的问题,我曾经设想的解决方案是在业务逻辑部分自己做一个缓存机制,在对数据进行增、删、改时同步更新数据缓存,这样调用程序不必关心数据究竟来自哪里。下面有一段示例代码:
        public class CContentManager
        {
            /// <summary>
            /// Caches the category list.
            /// </summary>
            private static ArrayList m_listCategories = null;        static CContentManager()
            {
                Initialize();
            }        private static void Initialize()
            {
                try
                {
                    m_listCategories = CDataAccess.ContentDataAccessInstance().GetAllCategories();
                }
                catch (Exception ex)
                {
                    CLogger.Trace(System.Diagnostics.TraceLevel.Error, ex);
                    m_listCategories =  new ArrayList();
                } 
            }        /// <summary>
            /// Can get all categories.
            /// </summary>
            /// <returns>The CCategory class list and If fail return empty arraylist.</returns>
            public static ArrayList GetAllCategories()
            {
                if (null == m_listCategories)
                {
                    Initialize();
                }
                return m_listCategories;
            }        /// <summary>
            /// Add a new column .
            /// </summary>
            /// <param name="name">columns name</param>
            /// <param name="parent">the column in database's parentID</param>
            /// <param name="type">columns type</param>
            /// <returns>result.</returns>
            public static bool AddCategory(string name,int parent,ECategoryType type)
            {
                bool returnvalue = false;
                try
                {
                    if (!string.IsNullOrEmpty(name))
                    {
                        CDataAccess.ContentDataAccessInstance().AddCategory(name, parent, 2, type, out returnvalue);
                        Initialize(); // 更新缓存内容
                    }
                }
                catch (Exception ex)
                {
                    CLogger.Trace(System.Diagnostics.TraceLevel.Error, ex);
                    return false;
                }
                return returnvalue;
               
            }