我在.Net 3.5和SqlHelper上使用Sql Server 2008 R2和VS 2008 C#。Sql server緩存問題
一種方法,比如updateData(int id)加載一些與「id」有關的數據,做了大量的計算和處理並重新提交數據。有一個單獨的程序doThings(int id),它執行一組任務,其中每個任務操作與「id」相關的數據,然後在一個事務中提交該數據。其中一些任務在提交後調用updateData(int id),但是,updateData(int id)不按照最新的提交更新數據。過了一會兒,如果我重新運行updateData(int id),那麼更新就完成了,因爲它應該。
爲了使它更清楚,這裏就是該程序是doing-
doTask(int id) //updates some table related to id and calls updateData()
doTask(int id) //updates some table related to id and calls updateData()
doTask(int id) //updates some table related to id and calls updateData()
doTask(int id) //updates some table related to id and calls updateData()
...
輸出 - 數據沒有更新
過了一會兒 -
updateData() //recalculates and updates the data
輸出 - 數據更新
我知道SQL Server緩存查詢結果集。但是,如果我更新了緩存中的表的一部分,那麼它不應該重新創建結果集。我已經在不同的環境(測試和生產)中嘗試過,沒有太多的幫助。
每個doTask(INT ID)的是利用交易來更新數據庫和交易完成SANS它,因爲它沒有最終的了updateData最後一次通話將不會更新數據。一旦交易完成,updateData()被調用,其也使用交易。有什麼與緩存有關的,可以在這裏幫助嗎?因爲我必須在這裏發佈的代碼量非常大,我甚至不允許這樣做。
我想兩兩件事,並在這兩個情況下─
- 工作增加500毫秒
- 調試的Thread.sleep代碼和剛剛第二呼叫舉行了到了updateData()在doTask()
不,還有其他事情正在發生。發佈一些代碼。 –