portletspec3
  1. portletspec3
  2. PORTLETSPEC3-19

Errata: Clarify when CacheControl parameters can be set

    Details

      Description

      CacheControl parameters need to be set in the HTTP header before the response is
      written.

      Working Document 3 (22.04.13) Section "PLT.22.2 Validation Cache", page 164 line 4 states:
      -------------------------
      The portlet should set the validation token, expiry time or caching scope before
      writing to the output stream as otherwise portals / portlet containers may ignore the
      values.
      -------------------------

      This is correct. However, the example right below that shows such parameters being set
      in the doView method:

      -------------------------
      protected void doView (RenderRequest request, RenderResponse response)
      throws PortletException, java.io.IOException
      {
      ...
      if ( request.getETag() != null ) { // validation request
      if ( markupIsStillValid(request.getETag()) ) {
      // markup is still valid
      response.getCacheControl().setExpirationTime(30);
      response.getCacheControl().setUseCachedContent(true);
      return;
      }
      }
      // create new content with new validation tag
      response.getCacheControl().setETag(someID);
      response.getCacheControl().setExpirationTime(60);
      PortletRequestDispatcher rd =
      getPortletContext().getPortletRequestDispatcher("jsp/view.jsp");
      rd.include(request, response);
      }
      -------------------------

      In general, this example would not work. Instead, the example code should
      appear in the doHeaders method, as follows:

      Corrected:
      -------------------------
      protected void doHeaders (RenderRequest request, RenderResponse response)
      {
      ...
      if ( request.getETag() != null ) { // validation request
      if ( markupIsStillValid(request.getETag()) ) {
      // markup is still valid
      response.getCacheControl().setExpirationTime(30);
      response.getCacheControl().setUseCachedContent(true);
      return;
      }
      }
      // create new content with new validation tag
      response.getCacheControl().setETag(someID);
      response.getCacheControl().setExpirationTime(60);
      PortletRequestDispatcher rd =
      getPortletContext().getPortletRequestDispatcher("jsp/view.jsp");
      rd.include(request, response);
      }
      -------------------------

        Activity

        msnicklous created issue -
        msnicklous made changes -
        Field Original Value New Value
        Assignee msnicklous [ msnicklous ]
        Neil Griffin made changes -
        Comment [ On a related note, [ResourceResponse.setContentLength(int)|http://portals.apache.org/pluto/portlet-2.0-apidocs/javax/portlet/ResourceResponse.html#setContentLength(int)] must be set before the response is written.

        The same technically holds true for:

        resourceResponse.setProperty(ResourceResponse.HTTP_STATUS_CODE, Integer.toString(statusCode));

        Does this merit any changes to the JavaDoc?
        ]
        Hide
        msnicklous added a comment -

        Updated spec document accordingly.

        Show
        msnicklous added a comment - Updated spec document accordingly.
        msnicklous made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Hide
        msnicklous added a comment -

        Fix discussed on 20130723 and was accepted.

        Show
        msnicklous added a comment - Fix discussed on 20130723 and was accepted.
        msnicklous made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            msnicklous
            Reporter:
            msnicklous
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: