【问题标题】:Appfabric caching for database dependency数据库依赖的Appfabric缓存
【发布时间】:2012-12-19 14:11:36
【问题描述】:

我们相信 AppFabric 缓存非常适合缓存要求。但是,我们还想实现某种数据库依赖,即缓存应该与后端数据库异步同步。 read-through and write behind 功能似乎很有趣,谁能帮我们指出一个方向,我们如何利用这些功能来实现 appfabric 和数据库之间的自动同步行为?非常感谢!

【问题讨论】:

    标签: appfabric


    【解决方案1】:

    SqlDependency 可用于通知您的应用程序有关数据库中的修改。要使用它,您需要在数据库级别启用服务代理,请在实施此解决方案之前通过这些limitation

    using (SqlConnection connection = new SqlConnection(yourConnectionString))
    {
        connection.Open();
    
        using (SqlCommand command = new SqlCommand(databaseSqlToBeMonitered, connection))
        {
           SqlDependency dependency = new SqlDependency(command);
           dependency.OnChange += new OnChangeEventHandler((a, b) =>
                                    {
                        //Remove data from cache
                                    });
    
           command.ExecuteReader().Close();
        }
    }
    

    【讨论】:

    • @PhilPursglove 这里说的是SqlDependency,这样我们就可以实现对依赖的支持了。我没有提到 AppFabric 支持依赖关系。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多