Appfabric caching for database dependency

爱⌒轻易说出口 提交于 2019-12-10 11:52:23

问题


We believe the AppFabric caching is a good fit for the caching requirement. However, we also want to implement some sort of database dependency, i.e. the cache should sync with the backend database asynchronously. The read-through and write behind feature seems interesting, could anyone please help point us a direction how can we leverage these features in achieving the auto sync behavior between the appfabric and database? Thanks a lot!


回答1:


SqlDependency can be used to notify to your application about modifications in database. To use this you need to enable service broker on database level, please go through these limitation before implementation this solution

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();
    }
}


来源:https://stackoverflow.com/questions/13844648/appfabric-caching-for-database-dependency

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!