[MGNLFORM-290] Add ability to cache pages with form components and make it configurable Created: 06/Nov/16 Updated: 18/Jan/24 |
|
| Status: | Open |
| Project: | Magnolia Form Module |
| Component/s: | None |
| Affects Version/s: | 2.7.2 |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Normal |
| Reporter: | Edwin Guilbert | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 1 |
| Labels: | cache-control, quickwin | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | 0.25h | ||
| Original Estimate: | Not Specified | ||
| Environment: | |||
| Issue Links: |
|
||||||||||||||||
| Template: |
|
||||||||||||||||
| Acceptance criteria: |
Empty
|
||||||||||||||||
| Task DoD: |
[ ]*
Doc/release notes changes? Comment present?
[ ]*
Downstream builds green?
[ ]*
Solution information and context easily available?
[ ]*
Tests
[ ]*
FixVersion filled and not yet released
[ ] 
Architecture Decision Record (ADR)
|
||||||||||||||||
| Documentation update required: |
Yes
|
||||||||||||||||
| Date of First Response: | |||||||||||||||||
| Epic Link: | AuthorX Support | ||||||||||||||||
| Team: | |||||||||||||||||
| 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. |
| Comments |
| Comment by Christopher Zimmermann [ 06/Nov/16 ] |
|
I cloned Edwin's suggestion box ticket and moved to FORMS module. |
| Comment by Richard Gange [ 28/Jan/21 ] |
|
DOC: Not only do we need to document the new setting but we need a short section on what else must be done if you use the noCahce = false option. The form component will need to use dynamic page caching. It could be enough to mention in the configuration chart's description area for the new property. |