ASP. NET cache implementation relies on Oracle's caching policy

Source: Internet
Author: User

The cache in ASP. NET provides support for SQL dependencies, which means that when the data in a table or row in a SQL Server database is changed, the pages in the cache are invalidated, otherwise the page output remains in the cache. This does provide convenience for programmers. But Microsoft has always been a petty, just for programmers who use their own product SQL Server, what about ASP. NET programmers who use Oracle databases?

In fact, there is no need to worry, because the cache in ASP. NET also provides support for file dependencies, that is, the cache relies on a file, the file is modified, the page in the cache is invalidated. You can easily implement an Oracle-dependent caching strategy by leveraging the ASP. Net file dependency caching policy and the triggers in Oracle. The idea is simple to set the page's caching policy to rely on a file, and then add a trigger for the tables in Oracle that need to be relied upon, and modify the contents of the file that the cache depends on when the data in the table is changed.

The following is a small example to specify:

Trial Purpose: The cache of the Default.aspx page relies on the Dept table of Scott users in the Oracle database, and the pages in the cache are invalidated after the data in the table has been changed. The cache expiration time is 120 seconds.

  First, set the cache of the site page depends on the file TextFile.txt

See System.Web.Caching.Cache-Class ASP. NET cache for various cache dependencies

Ii. creating triggers in the Oracle database

1. Execute PL/SQL code block when trigger is triggered. The PL/SQL code block directly reads and writes files from the operating system, calling the built-in Utl_file package. This requires first modifying the Oracle initialization parameter file Init.ora, where the parameter utl_file_dir is added to specify the directory of the file. After modifying the Init.ora file, you need to restart the Oracle database to set the parameters to take effect.

Add the following line to the Init.ora file:

Utl_file_dir= ' E:/csharp/cachebyoracledependncy '

It can also be set to utl_file_dir=*, without specifying a specific directory, that is, any directory.

In the case of Oracle 9i databases, there is another way to do the same: Create a directory directory under the SYS user (actually add a corresponding os_path to the dir$ table under the SYS user) and then read/ Permission to write operation Grant to public.

[SQL]View PlainCopy
    1. Create or replace directory FILEPATH as ' e:/csharp/cachebyoracledependncy ';
    2. Grant read on directory FILEPATH to public ;


Here I am using the second method.

2. Create a trigger for the table you depend on (the Dept table for the Scott user): When the data in the Dept table changes, the trigger writes the current system time to the TextFile.txt file.

[SQL]View PlainCopy
  1. CREATE OR REPLACE TRIGGER
  2. "SCOTT". "Test_cache_by_oracle_dependncy" after
  3. INSERT
  4. OR UPDATE
  5. OR DELETE of "DEPTNO", "Dname", "LOC" on "SCOTT"." DEPT " DECLARE
  6. File_handle Utl_file.file_type;
  7. BEGIN
  8. --Open File
  9. File_handle: = Utl_file.fopen (' FILEPATH ',' TextFile.txt ',' W ');
  10. --Write the current system time to the file
  11. IF Utl_file.is_open (file_handle) Then
  12. Utl_file.put_line (File_handle,to_char (sysdate,' Yyyy-mm-dd hh24:mi:ss '));
  13. END IF;
  14. --Close File
  15. Utl_file.fclose (File_handle);
  16. EXCEPTION
  17. When OTHERS then
  18. BEGIN
  19. IF Utl_file.is_open (file_handle) Then
  20. Utl_file.fclose (File_handle);
  21. END IF;
  22. EXCEPTION
  23. When OTHERS then
  24. NULL;
  25. END;
  26. END;


If the application server and the database server are not the same server, you may experience dependencies where the project cannot successfully access the file:

The workaround is described in ASP. NET access to network drives (mapped disks)

ASP. NET cache implementation relies on Oracle's caching policy

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.