DBPrism Servlet Engine
External Cache Invalidator Server interface
Definition:

The External Cache Invalidator Class implements a new modality for Cocoon2's cache System. It provides a new way to invalidate cached pages stored into Cocoon cache system with a simple external message interpreted by an XSP page. It mean that you could generate a dynamic page with DBPrism or with an XSP page and stored it into the Cocoon Cache system, this page will remaind valid into the cache until an XML message says to this server implementation that the stored page is no longer valid, when a new request come to Cocoon it will generate a new one. This kind of synchronization is commonly implemented through triggers into the database that provides the information for the dynamic page.

This interface defines a role for every possible implementation of an External Cache Invalidator Server functionality. It defines a role for the Avalon roles, and it also needs to modify cocoon.roles file included into cocoon.jar or user.roles file, here the sample entry.

<role name="org.apache.cocoon.components.cache.Server"
                       shorthand="cache-server"
                       default-class="org.apache.cocoon.components.cache.DatabaseServerImpl"/>
DatabaseServerImpl class is a concrete class which implements the defined contract using HSQL database for storing the cached pages metadata, other implementation could be added in a short future providing faster implementation for accessing and invalidating higher amount of cached pages.
Methods:
  • public boolean isRegistered( ESIKey key) , Returns true or false if the key argument is registered as a Cached Page.
  • public long getCacheablePageKey(ESIKey key), Returns a long value used by Cocoon's cache system to locate a Cached Page.
  • public void registerCacheablePage(ESIKey key), Registers a Cached Page, this page is identified by an ESIKey object which holds the URL for this page, his encoded argument and the long value used by Cocoon's cache system to identified the cached page.
  • public int removeCacheablePage(String username, String password, String URI, String URIRegExp, ESIKey key, int ttl), Removes a previous cached page identified by the URI path, the URIRegExp regular expresion and the encoded arguments, it requires a valid username and password to access to the cache server. This method do not remove automatically the page, it stores the ESIKey into a queue of pages to invalidate, this queue is cheked every 1 second by default. See DatabaseServerImpl section for more details. ttl (or time-to-live) value is reserved for future use. URI is a base path for the page(s) to be remove. URIRegExp is a regular expresion used for matching with the page(s) to remove
Note about URI and URIRegExp:

URI       = /p1/p2/p3/ and
URIRegExp = ^/p1/p2/p3/file.htm$ or
URI       = / and
URIRegExp = ^/p1/p2/p3/file.htm$
match with the same page 
        
          
        
          
        
          
        
          
        
          
        
          /p1/p2/p3/file.htm.
Since the regular expression is done against the set of page objects containing
the common URIPREFIX path prefix, it is obvious that the smaller the set,
the more efficient the invalidation.
        
      
        
      
        
      
        
      
        
      
        
      
        
Constants
  • ROLE, Defines Avalon Role for this server.
  • NONE, EXTERNAL, NOP, Used by DBPrismGenerator to identified three kind of cacheability rules. None means that the page is no cacheable, External means that the page is controled by the External Cache Invalidator Server and the method generateValidity() will return an instance of ExternalCacheValidity object, NOP means that the page is cacheable and will remains in the Cocoon cache during the life of Cocoon instance (generateValidity() will return an object of type NOPCacheValidity).
  • COPY_ARG_NAME, Used by the CocoonRequestWrapper to merge the standard servlet http request arguments with the sitemap arguments.
  • COPY_NO and COPY_YES, Special values used into Copy-Request-Arguments, false mean that only pass DBPrismGenerator sitemap parameters, true mean that all the http arguments and cookies are passed to the DBPrismGenerator.
  • CACHE_CONTROL_ARG_NAME, Its the name on the sitemap argument that defines the cacheability behaviour on DBPrismGenerator.
  • CACHE_CONTROL_EXTERNAL, CACHE_CONTROL_NOP, CACHE_CONTROL_NONE, Values defined for the previous one argument on the sitemap syntax.
ESI Ivalidation Messages

These examples shows invalidation request for doing ESI invalidation of cached page documents. An invalidation request is an XML document sent over HTTP using HTTP/1.1 POST method. The syntax for an invalidation request is dictated by WCSinvalidation.dtd DTD (Document Type Definition).

This XSP Page listens for incomming request of invalidation pages, and contacts the Invalidator Server instance for invalidating the given page.

DBPrism External Cache Invalidator XSP page uses ESI Advanced Selector for invalidating Cocoon pages, to define parameters either sitemap parameter or http parameter uses tags of type OTHER, selecting sitemap or http values for the attribute type.
Basic Selector Example

This selector shows how to invalidate an XSP page which includes the necesary code to register this page as External Invalidated.

POST /dbprism/x-dbprism-cache-invalidate HTTP/1.0
Authorization: BASIC aW52YWxpZGF0b3I6aW52YWxpZGF0b3I=
Content-Length: 213

<?xml version="1.0"?>
<INVALIDATION VERSION="WCS-1.0">
  <OBJECT>
    <BASICSELECTOR URI="/ext/xsp/simple_ext"/>
    <INFO VALUE="simple_ext.xsp"/>
    <ACTION REMOVALTTL="0"/>
  </OBJECT>
</INVALIDATION>
If you press reload button on the browser bar, the botton part of the page will never change until you sent the above invalidation message,
id_user is used as customization argument, it means that Cocoon will stored differents pages for every different argument value of id_user. The above invalidation message will invalidate all the pages independent of the customization argument.

Here a sequence of unix commands using the simple telnet program to contact Cocoon's External Invalidator Server and invalidating the previous one XSP page.

[oracle8i@p1 dbprism]$ telnet localhost 8888                      
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
POST /dbprism/x-dbprism-cache-invalidate HTTP/1.0
Authorization: BASIC aW52YWxpZGF0b3I6aW52YWxpZGF0b3I=
Content-Length: 213

<?xml version="1.0"?>
<INVALIDATION VERSION="WCS-1.0">
  <OBJECT>
    <BASICSELECTOR URI="/ext/xsp/simple_ext"/>
    <INFO VALUE="simple_ext.xsp"/>
    <ACTION REMOVALTTL="0"/>
  </OBJECT>
</INVALIDATION>
HTTP/1.1 200 OK
Date: Fri, 04 Jul 2003 12:33:31 GMT
Server: Oracle9iAS (9.0.3.0.0) Containers for J2EE
Connection: Close
Content-Type: text/html
X-Cocoon-Version: 2.0.4

<INVALIDATIONRESULT VERSION="WCS-1.0" xmlns:xsp="http://apache.org/xsp">





<OBJECTRESULT>
<BASICSELECTOR URI="/ext/xsp/simple_ext"></BASICSELECTOR>
<RESULT ID="0" STATUS="SUCCESS" NUMINV="2"></RESULT>
</OBJECTRESULT>

</INVALIDATIONRESULT>
Connection closed by foreign host.
[oracle8i@p1 dbprism]$
Advanced Selector Example
POST /dbprism/x-dbprism-cache-invalidate HTTP/1.0
Authorization: BASIC aW52YWxpZGF0b3I6aW52YWxpZGF0b3I=
Content-Length: 450

<?xml version="1.0"?>
<INVALIDATION VERSION="WCS-1.0">
  <OBJECT>
    <ADVANCEDSELECTOR URIPREFIX="/ext/xsp/" URIEXP="simple_ext">
      <OTHER TYPE="sitemap" NAME="test_param1" VALUE="test1"/>
      <OTHER TYPE="sitemap" NAME="test_param2" VALUE="test2"/>
      <OTHER TYPE="http" NAME="id_user" VALUE="user1"/>
    </ADVANCEDSELECTOR>
    <INFO VALUE="simple_ext.xsp?id_user=1"/>
    <ACTION REMOVALTTL="0"/>
  </OBJECT>
</INVALIDATION>

The above example will invalidate the XSP page /ext/xsp/simple_ext located under the path /ext/xsp/, only if the sitemap and http parameters match with the values provided, in this example, if the personalized attribute was id_user, pages with id_user not equal to user1 will remains valid into the cache system.

Advanced Selector Example, using regular expresions
POST /dbprism/x-dbprism-cache-invalidate HTTP/1.0
Authorization: BASIC aW52YWxpZGF0b3I6aW52YWxpZGF0b3I=
Content-Length: 392

<?xml version="1.0"?>
<INVALIDATION VERSION="WCS-1.0">
  <OBJECT>
    <ADVANCEDSELECTOR URIPREFIX="/ext/xsp/" URIEXP="simple.*">
      <OTHER TYPE="sitemap" NAME="test_param1" VALUE="test1"/>
      <OTHER TYPE="sitemap" NAME="test_param2" VALUE="test2"/>
    </ADVANCEDSELECTOR>
    <INFO VALUE="all_simple_under_ext_xsp"/>
    <ACTION REMOVALTTL="0"/>
  </OBJECT>
</INVALIDATION>

The above example will invalidate the content of the XSP pages that match with the regular expresion simple.* and located under the path /ext/xsp/, it means that, indepent of the personalized attribute (id_user) the pages that match with the sitemap parameters (test_param1 and test_param2) and regular expresion will be removed from the cache..

This work is licensed under a Creative Commons License . Creative Commons License
(C) 1999-2008 - DBPrism ~ DBPrism CMS | Marcelo F. Ochoa | TANDIL ~ Argentina | 2008-10-07T20:12:49
DBPrism at SourceForgeBuilt with Cocoon2