Implementing Validation-Based Caching Improving Portlet Performance with Caching

Creating PLSQL Portlets 8-35 p_portlet_record.caching_key := MY_INITIAL_CACHE_KEY; end if; 8. Optionally, if you want to see this portlet on a page and it is not already in the Portlet Repository, refer to the instructions in Section 8.3.2, Implementing the Provider Package for information on how to add it. 9. Once your portlet appears in the repository, you can add it to a page to test it. To add your portlet to a page, follow the instructions in Oracle Fusion Middleware Users Guide for Oracle Portal.

8.8.4 Implementing Expiry-Based Caching

The caching example, located in ..\pdkplsql\pdk\plsql\cache in PDK-PLSQL pdkplsql.zip, illustrates how you can implement expiry-based caching. You can browse through this example as follows to see how the expiry-based functions are implemented in a portlet: 1. Open the expirycache_portlet.pkb file in an editor. 2. At the very top of the file, notice the aliases for the caching level constants. CREATE OR REPLACE package body VALIDCACHE_PORTLET is -- Caching Constants CACHE_LEVEL_SYSTEM constant varchar210 := SYSTEM; CACHE_LEVEL_USER constant varchar210 := USER; 3. Find the show procedure. Notice first that the p_portlet_record is an in and out parameter for this procedure. procedure show p_portlet_record in out wwpro_api_provider.portlet_runtime_record 4. In the procedures security check, the caching fields of p_portlet_record are set to null if the security check fails. begin if not is_runnable p_provider_id = p_portlet_record.provider_id ,p_reference_path = p_portlet_record.reference_path 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.PORTLET_SECURITY_EXCEPTION; end if; 5. After that, the procedure sets the value of the caching period in minutes in a temporary variable: -- Set the Caching Period to one minute l_cache_period := 1; 6. Next, notice how the code checks your portlet_runtime_record parameter for the current values of the caching_period and sets the caching_period accordingly. This same piece of code can compare your caching_period values. if p_portlet_record.caching_level = CACHE_LEVEL_SYSTEM then 8-36 Oracle Fusion Middleware Developers Guide for Oracle Portal -- Cache does not exists for the user, create it p_portlet_record.caching_level := CACHE_LEVEL_USER; p_portlet_record.caching_period := l_cache_period; elsif p_portlet_record.caching_level = CACHE_LEVEL_USER then -- Cache exists for the user, overwrite it p_portlet_record.caching_period := l_cache_period; elsif p_portlet_record.caching_level is null then if p_portlet_record.caching_period is not null then -- Cache does not exists for the user, create it p_portlet_record.caching_level := CACHE_LEVEL_USER; p_portlet_record.caching_period := l_cache_period; else -- Define a sytem cache. This can happen only once p_portlet_record.caching_level := CACHE_LEVEL_SYSTEM; p_portlet_record.caching_period := l_cache_period; end if; else -- p_portlet_record.caching_level value is messed up p_portlet_record.caching_level := CACHE_LEVEL_SYSTEM; p_portlet_record.caching_period := l_cache_period; end if; 7. Optionally, if you want to see this portlet on a page and it is not already in the Portlet Repository, refer to the instructions in Section 8.3.2, Implementing the Provider Package for information on how to add it. 8. Once your portlet appears in the repository, you can add it to a page to test it. To add your portlet to a page, follow the instructions in Oracle Fusion Middleware Users Guide for Oracle Portal.

8.8.5 Implementing Invalidation-Based Caching

Suppose you have a portlet that displays a map of the world, map_portlet.pkb and map_portlet.pks. You would go about adding invalidation-based functions to it as follows: 1. In the show procedure, you need to add a call to wwpro_api_provider.use_ invalidation. This call indicates to Oracle Portal that the portlet content should be cached by Oracle Web Cache. Note that we have also specified that the content be cached at the user level and that expiry-based caching be used as well that is, an expiration interval of one minute has been set. procedure show ... if p_portlet_record.exec_mode = wwpro_api_provider.MODE_SHOW then p_portlet_record.caching_invalidation := wwpro_api_provider.use_invalidation; p_portlet_record.caching_level := USER; p_portlet_record.caching_period := 1; ... 2. Create a procedure in your map_portlet.pkb file that invalidates the cache. For example: procedure map_invalidation p_provider_id in number, p_portlet_id in number, p_instance_id in varchar2, p_page_url in varchar2 Creating PLSQL Portlets 8-37 is begin wwpro_api_invalidation.invalidate_by_instance p_provider_id = p_provider_id, p_portlet_id = p_portlet_id, p_instance_id = p_instance_id, p_user = wwctx_api.get_user; owa_util.redirect_urlp_page_url; end map_invalidation; 3. In the show procedure, add a link for refreshing the portlet before the code that draws the map. For example: Draw the Refresh Me link htp.anchor curl = wwctx_api.get_user|| .map_invalidation?p_provider_id=||p_portlet_record.provider_id|| p_portlet_id=||p_portlet_record.portlet_id|| p_instance_id=||p_portlet_record.reference_path|| p_page_url=||utl_url.escape url = p_portlet_record.page_url, escape_reserved_chars = TRUE, ctext = wwui_api_portlet.portlet_text p_string =Refresh Me, p_level = 1 ; 4. Optionally, if you want to see this portlet on a page and it is not already in the Portlet Repository, refer to the instructions in Section 8.3.2, Implementing the Provider Package for information on how to add it. 5. Once your portlet appears in the repository, you can add it to a page to test it. To add your portlet to a page, follow the instructions in Oracle Fusion Middleware Users Guide for Oracle Portal.

8.9 Implementing Error Handling

Oracle Portal provides the capability for you to trap erroneous input and return meaningful error messages. It manages the internal error stack by tracking the raised exceptions and retaining information about them. Oracle Portal also includes a set of APIs for presenting errors in a standardized way. Error handling services are available through the wwerr_api_error and wwerr_ api_error_ui packages. These error handling services include the following key features: ■ Error stack . Oracle Portal uses an error stack to keep track of the error messages. When an error occurs, the error message is pushed onto an error stack. Whenever procedures or function calls are nested, the error stack keeps track of all the error messages. You can choose to retrieve only the top error or most recent error by using the wwerr_api_error.get_top method. Alternatively, you can get all the error messages on the stack using the wwerr_api_error.get_errors function. The stack can also be checked for the presence of any errors by calling the wwerr_api_error.is_empty function. ■ Error messages . Error handling services provide a way to define meaningful error messages. To define your own error messages, you need to define their name space. The name space consists of the following: – Name is the error name.