Oracle 9i Application Server Using the PL/SQL Gateway Release 1 (v1.0.2.2) Part Number A90099-01 |
|
Caching can improve performance of your PL/SQL Web applications. You can cache Web content generated by PL/SQL procedures in the middle-tier and decrease the database workload.
Text description of the illustration cachov.jpg
Refer to the Caching Overview diagram above during the discussion of caching. It illustrates the different techniques used in caching. For example:
These techniques and levels are implemented using owa_cache packages located inside the PL/SQL Web Toolkit, represented in the diagram by the toolkit in the database.
In general, the validation technique basically asks the server if the page has been modified since it was last presented. If it has not been modified, the cached page will be presented to the user. If the page has been modified, a new copy will be retrieved, presented to the user and then cached.
There are two methods which use the Validation Technique, Last-Modified method and the Entity Tag method. The next two sections show how these techniques are used in the HTTP protocol. Although the PL/SQL Gateway does not use the HTTP protocol, many of the same are principles are used.
Using the HTTP protocol, when a Web page is generated, it contains a Last-Modified Response Header. This header indicates the date (relative to the server) of the content that was requested. Browsers save this date information along with the content. When subsequent requests are made for the URL of the Web page, the browser:
Cache-enabled servers look for the If-Modified-Since header and compare it to their content's date. If the two match, an HTTP Response status header such as "HTTP/1.1 304 Not Modified" is generated, and no content is streamed. Upon receipt of this status code, the browser can reuse its cache entry because it has been validated.
If the two don't match, an HTTP Response header such as "HTTP/1.1 200 OK" is generated and the new content is streamed, along with a new Last-Modified Response header. Upon receipt of this status code, the browser must replace its cache entry with the new content and new date information.
Another validation method provided by the HTTP protocol is the ETag (Entity Tag) Response and Request header. The value of this header is a string that is opaque to the browser. Servers generate this string based on their type of application. This is a more generic validation method than the If-Modified-Since header, which can only contain a date value.
The ETag method works very similar to the Last Modified method. Servers generate the ETag as part of the Response Header. The browser stores this opaque header value along with the content that is steamed back. When the next request for this content arrives, the browser passes the If-Match header with the opaque value that it stored to the server. Because the server generated this opaque value, it is able to determine what to send back to the browser. The rest is exactly like the Last-Modified validation method as described above.
Using HTTP validation caching as a framework, the following is the Validation Model for the PL/SQL Gateway.
PL/SQL applications that want to control the content being served should use this type of caching. This technique offers some moderate performance gains. One example of this would be an application that serves dynamic content that can change at any given time. In this case, the application needs full control over what is being served. Validation caching always asks the application whether the cached content is stale or not before serving it back to the browser.
Text description of the illustration cachv.jpg
owa_cache.set_cache(p_etag, p_level);
Using the same validation model explained above, a second request is made by the client browser for the same PL/SQL procedure.
Text description of the illustration cachv2.jpg
owa_cache
functions from the PL/SQL Web Toolkit:
owa_cache.get_etag;
owa_cache.get_level;
These owa functions get the tag and caching level.
owa_cache.set_not_modified
procedure and generates no content. This PL/SQL Gateway to use its cached content. The cached content is directly streamed back to the browser.
In the validation model, the PL/SQL Gateway always asks the PL/SQL procedure if it can serve the content from the cache. In the expires model, the procedure preestablishes the content validity period. Therefore, the PL/SQL Gateway can serve the content from its cache without asking the procedure. This further improves performance because no interaction with the database is required.
This caching technique offers the best performance. Use if your PL/SQL application is not sensitive to serving stale content. One example of this is an application that generates news daily. The news can be set to be valid for 24 hours. Within the 24 hours, the cached content is served back without contacting the application. This is essentially the same as serving a file. After 24 hours, the PL/SQL Gateway will again fetch new content from the application.
Assume the same scenario described above for the Validation model, except the procedure uses the Expires model for caching.
Text description of the illustration expires.jpg
owa_cache.set_expires(p_expires, p_level);
Using the same expires model explained above, a second request is made by the client browser for the same PL/SQL procedure.
Text description of the illustration expire2.jpg
A PL/SQL procedure determines whether generated content is system-level content or user-level. This helps the PL/SQL Gateway cache to store less redundant files if more than one user is looking at the same content. It decides this by:
Authentication Mode | Type of User |
---|---|
Single Sign On (SSO) |
Lightweight user |
Basic |
Database user |
Custom |
Remote user |
For example, if no user customizes a PL/SQL Web application, then the output can be stored in a system-level cache. There will be only one cache copy for every user on the system. User information is not used since the cache can be used by multiple users.
However, if a user customizes the application, a user-level cache is stored for that user only. All other users still use the system level cache. For a user-level cache hit, the user information is a criteria. A user-level cache always overrides a system-level cache.
Your decision whether to use the Validation technique or the Expires technique determines which owa_cache functions to call.
The owa_cache package contains procedures to set and get special caching headers and environment variables. These allow developers to use the PL/SQL Gateway cache more easily. This package should already be installed in your database.
These are the primary functions to call:
|
![]() Copyright © 2001 Oracle Corporation. All Rights Reserved. |
|