asp.net 2.0中的緩存提供了對sql依賴項的支持,也就是說當sql server數據庫中的表或行中的數據被更改后,緩存中的頁面就失效,否則,頁面輸出可一直保留在緩存當中。這確實為程序員提供了方便。但微軟一向很小家子氣,只為使用自家產品sql server的程序員提供了方便,那些用oracle數據庫的asp.net程序員怎么辦呢?
1、打開visual studio 2005,在e:/csharp/cachebyoracledependncy目錄下新建一個web項目,在其default.aspx頁面上添加一個label控件,顯示頁面生成的時間,以判斷刷新時頁面是否為重新生成的,并設置頁面緩存依賴于文件e:/csharp/cachebyoracledependncy/textfile.txt。
create or replace trigger "scott"."test_cache_by_oracle_dependncy" after insert or update or delete of "deptno", "dname", "loc" on "scott"."dept" declare file_handle utl_file.file_type; begin --打開文件 file_handle := utl_file.fopen('filepath','textfile.txt','w'); --將當前系統時間寫入文件 if utl_file.is_open(file_handle) then utl_file.put_line(file_handle,to_char(sysdate,'yyyy-mm-dd hh24:mi:ss')); end if; --關閉文件 utl_file.fclose(file_handle); exception when others then begin if utl_file.is_open(file_handle) then utl_file.fclose(file_handle); end if; exception when others then null; end; end;
在visual studio 2005中調試程序,不斷刷新打開的default.aspx頁面,頁面顯示的時間每隔120秒,才會發生變化一次。這是因為設置的緩存過期時間為120秒。這時,只要我們手工修改scott用戶的dept表中的數據后,再次刷新頁面時,頁面上顯示的時間馬上就會發生變化。這說明我們設置的依賴oracle的緩存策略成功了。