Uploaded image for project: 'Magnolia Form Module'
  1. Magnolia Form Module
  2. MGNLFORM-290

Add ability to cache pages with form components and make it configurable

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Unresolved
    • Normal
    • None
    • 2.7.2
    • None
    • Yes

    Description

      Original description "Pages with form components (Form Module) should be cacheable by config"

      It's a common use case to have forms in pages you need to be cached. Cache strategies are available for any page in Magnolia and that can be managed just by config.

      The problem comes when you try to enable caching on a page containing form components from the Magnolia Form Module, because no matter what config you have in the cache module policies, it will get overriden by a line of code in AbstractFormModel#execute():

      if (MgnlContext.isWebContext()) {
          MgnlContext.getWebContext().getResponse().setHeader("Cache-Control", "no-cache");
      }
      

      Even though this is a good practice in the sense that the form component can't ever be cached or it will run into known issues, there should be an easy way to disable this behaviour in order to be able to cache the page containing this component. Later on you could apply other strategies to update (or not cache) just the form element from the page by for example requesting this component by Ajax every time the page is loaded or just using the Dynamic Page Caching in Magnolia 5.4.5+

      We need a "config easy way" of disabling this default behaviour of form components. Right now the only way is by overriding the whole AbstractFormModel because it can't be properly extended. Its using private global attributes inside the execute method so you have to override all methods from the class, otherwise you will get NPEs. See the example class attached.

      This option is really bad in general because it has maintainability issues: whenever you update the form module you will have to check if the original class changed to make the same changes in your copy.

      I also attached another class approach (extending the execute method and just resetting the header) but this one will reset the cache-control header which is wrong in general because none of the browser cache policies get applied to the response of the page.

      What we need is a refactoring of the AbstractFormModel class allowing the cache functionality to be managed by config.

      Checklists

        Acceptance criteria

        Attachments

          Issue Links

            Activity

              People

                Unassigned Unassigned
                ebguilbert Edwin Guilbert
                AuthorX
                Votes:
                1 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                  Created:
                  Updated:

                  Checklists

                    Task DoD

                    Time Tracking

                      Estimated:
                      Original Estimate - Not Specified
                      Not Specified
                      Remaining:
                      Remaining Estimate - Not Specified
                      Not Specified
                      Logged:
                      Time Spent - 0.25h
                      0.25h