| Last Update: | Aug 04, 2003 |
| Status: | Production |
| Version: | Any PDK Release |
Oracle9iAS Portal provides functionality for caching of PL/SQL portlets. This functionality permits PL/SQL portlets to have their Web content cached by the middle tier. Subsequent requests for the content may be retrieved from the cache, with or without validation from the database, decreasing the database workload.
Oracle9iAS Portal provides two ways to enable caching in your PL/SQL portlets. You can either choose to use Validation based caching or Expiry based caching. The first method compares a key value to check whether the cache is still valid. If the key value doesn't change, it uses the cached content otherwise it makes a round trip to the Portal node to fetch the portlet content. The second method uses a given expiration period to use the cache for rendering the portlet.
This article describes how Validation based caching can be implemented in your portlets. It provides a guideline for adding caching to your portlet functionality.Before you can start using Caching, it must be enabled in your Portal installation. The section on 'How to Enable Caching' in the article A Primer on Caching explains how this setup can be done.
The general model for using Caching can be described as follows:
CREATE OR REPLACE
package body VALIDCACHE_PORTLET
is
-- Caching Constants --
CACHE_LEVEL_SYSTEM constant varchar2(10) := 'SYSTEM';
CACHE_LEVEL_USER constant varchar2(10) := 'USER';
function get_portlet_info
(
p_provider_id in integer
,p_language in varchar2
)
return wwpro_api_provider.portlet_record
is
l_portlet wwpro_api_provider.portlet_record;
begin
l_portlet.id := cache_provider.PORTLET_VALIDCACHE;
l_portlet.provider_id := p_provider_id;l_portlet.title := 'Validation Based Caching';
l_portlet.name := 'Validation_Cache';
l_portlet_descriptin := 'This portlet illustrates validation based caching';
...
end VALIDCACHE_PORTLET;
/
CREATE OR REPLACE
package body VALIDCACHE_PORTLET
is
...
procedure show
(
p_portlet_record in out wwpro_api_provider.portlet_runtime_record
)
is
l_portlet wwpro_api_provider.portlet_record;begin
-- Perform the Security Check
if not is_runnable(p_provider_id, null)
then
-- Set it to null so that cache does not get used even if exists
p_portlet_record.caching_level := null;
p_portlet_record.caching_key := null;
raise wwpro_api_provider.PROVIDER_SECURITY_EXCEPTION;
end if;
--
-- CHECK CACHE IS VALID
--
l_cache_key := get_cache_key();
...
end show;
end VALIDCACHE_PORTLET;
/
CREATE OR REPLACE
package body VALIDCACHE_PORTLET
is
...
-- Key is substring of time, upto the first digit of the seconds
-- which is effectively the YYYY:MM:DD:HH:MI:S string.
-- This ensures that the portlet is cached for 10 seconds at least,
-- till the new key value has a changed value for the first digit
-- of the seconds field.
function get_cache_key
return varchar2
is
l_date date;
begin
select sysdate into l_date from dual;
return trim(substr(to_char(l_date, 'YYYY:MM:DD:HH:MI:SS'), 1, 18));
exception
when others then
null;
end get_cache_key;
...
end VALIDCACHE_PORTLET;
/
CREATE OR REPLACE
package body VALIDCACHE_PORTLET
is
...
procedure show
(
p_portlet_record in out wwpro_api_provider.portlet_runtime_record
)
...
l_cache_key := get_cache_key();
-- SYSTEM CACHE is nothing but an empty portlet. The user has done
-- nothing yet!
if p_portlet_record.caching_level = CACHE_LEVEL_SYSTEM then
if l_cache_key is not null then
-- Cache exists for the user, overwrite it
p_portlet_record.caching_level := CACHE_LEVEL_USER;
p_portlet_record.caching_key := l_cache_key;
else
return; -- System cache is still valid.
end if;
elsif p_portlet_record.caching_level = CACHE_LEVEL_USER then
if p_portlet_record.caching_key != l_cache_key then
-- Cache has expired, reset it
p_portlet_record.caching_key := l_cache_key;
else
return; -- User cache is still valid.
end if;
elsif p_portlet_record.caching_level is null then
if p_portlet_record.caching_key is not null then
-- Cache does not exist for the user, create it
p_portlet_record.caching_level := CACHE_LEVEL_USER;
p_portlet_record.caching_key := l_cache_key;
else
-- Define a system cache. This can happen only once!
-- the first time the portlet is rendered.
p_portlet_record.caching_level := CACHE_LEVEL_SYSTEM;
p_portlet_record.caching_key := 'MY_INITIAL_CACHE_KEY';
end if;
else -- p_portlet_record.caching_level value is messed up!
p_portlet_record.caching_level := CACHE_LEVEL_SYSTEM;
p_portlet_record.caching_key := 'MY_INITIAL_CACHE_KEY';
end if;
if (p_portlet_record.exec_mode = wwpro_api_provider.MODE_SHOW) then
...
end show;
...
end VALIDCACHE_PORTLET;
/
| Revision History: |
|
| Oracle Corporation World Headquarters 500 Oracle Parkway Redwood Shores, CA 94065, USA http://www.oracle.com/ |
Worldwide Inquiries: 1-800-ORACLE1 Fax 650.506.7200 |
Copyright and Corporate Info |