[MGNLADVCACHE-90] Double call components with advanced cache. Created: 09/Jun/17  Updated: 17/Jul/17  Resolved: 17/Jul/17

Status: Closed
Project: Advanced Cache
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Neutral
Reporter: Vyacheslav Maksimov Assignee: Roman Kovařík
Resolution: Workaround exists Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

tomcat-8.5.5, java8, ubuntu 16.04. Connected molules: sitemesh, advancedcache and memcached implementation.


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)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:

 Description   

I have a component with defined fragmentDefinition. I request the magnolia component on the client side from the external system, as shown in https://documentation.magnolia-cms.com/display/DOCS/Rendering+content in the "Direct component rendering" section.

As a result, there are next problems:
1) When URL is requested, for example http://local.mvideo.ru:8080/magnoliaPublic/travel/main/0, the key with uri=/magnoliaPublic/travel/main/0 will be stored in the cache, request marked as CachePolicyResult.useCache and then dynamic fragment will be called, the same key(/magnoliaPublic/travel/main/0) is saved in the cache. Thus, double saving of data with the same key in the cache.
2) Also, when URL is requested, the page or component is rendered ftl and put data in the browsercache, then the component with fragmentDefinition is rendered ftl again. As a result, there are two calls to render the same component. It is the overhead. You must avoid double-calling the same data.



 Comments   
Comment by Roman Kovařík [ 12/Jun/17 ]

Hi mrslavutich,

  1. I believe the URI of the key is different, but not the other parts of the keys (headers...) otherwise the item would be retrieved from cache.
  2. Why is your component marked as dynamic even though you're calling the component directly (/magnoliaPublic/travel/main/0) thus you don't need the dynamic page caching, right?

Could you share your use case and version of advanced cache and sitemesh you're using?

Thanks in advance.
Roman

Comment by Vyacheslav Maksimov [ 13/Jun/17 ]

Hi, Roman Kovařík
Yes, everything is so, the keys are the same and on the second call will be extraction from cache. The double call brings costs.
I need to use every component with my own ttl, therefore i marked as dynamic. How else can I cache components with different ttl?

I have the external website that calls on the client side of the magnolia component on the url = http://localhost:8080/main/0. The component defined in the buyNowSection.yaml:

templateScript: /integration-mvideo/templates/components/home/buyNowSection.ftl
renderType: freemarker
title: Buy Now
dialog: integration-mvideo:productsBuyNow
modelClass: ru.mvideo.modules.integration.model.ProductBuyNowModel
fragmentDefinition:
dynamic: true
class: info.magnolia.module.advancedcache.rendering.DynamicFragmentDefinition
ttl: 900
mechanism: sitemesh

advancedcache:1.8.2
sitemesh:1.1.1

Thanks.

Comment by Roman Kovařík [ 13/Jun/17 ]

Hi,
you can use the cache instructor in your model class:

    public class ProductBuyNowModel {
        private final Provider<CacheInstructor> cacheInstructorProvider;

        @Inject
        ProductBuyNowModel(..., Provider<CacheInstructor> cacheInstructorProvider) {
            ...
            this.cacheInstructorProvider = cacheInstructorProvider;
        }

        @Override
        public void execute() {
            cacheInstructorProvider.get().setTtl(100);
        }
    }

Than you don't need to use the DPC at all.

Hope that helps.

Comment by Vyacheslav Maksimov [ 13/Jun/17 ]

Ok, thank you, but i still have to customize RenderableDefinition to include your ttl. In my opinion, it would be nice to include in the overall core functionality.

Returning to the second topic, double component rendering. I have another case, there is a page with the product, which contains several components:
productDetail.yaml:
templateScript: /integration-mvideo/templates/components/product/productDetail.ftl
renderType: freemarker
title: product detail
areas:
pageTop:
renderType: freemarker
availableComponents:
pageTopSection:
id: integration-mvideo:components/product/pageTop
contentPrimary:
renderType: freemarker
availableComponents:
productContentPrimary:
id: integration-mvideo:components/product/productContentPrimary
contentSecondary:
renderType: freemarker
availableComponents:
productDetailsBestPrice:
id: integration-mvideo:components/product/productBestPrice
productDetailSummary:
id: integration-mvideo:components/product/productDetailSummary
productAdditionalInfo:
renderType: freemarker
availableComponents:
productAdditionalInfo:
id: integration-mvideo:components/product/productAdditionalInfo

pageTop.yaml:
templateScript: /integration-mvideo/templates/components/htmlBlock.ftl
renderType: freemarker
title: Page top htmlSection
dialog: integration-mvideo:createHtmlBlock
fragmentDefinition:
dynamic: true
class: info.magnolia.module.advancedcache.rendering.DynamicFragmentDefinition
ttl: 600
mechanism: sitemesh

And so on.

   At the initial request in the browser, all components are rendered and cached, then the second request(if CachePolicyResult.useCache = true) again renders the same components marked as dymanic and this is a problem. I think you should avoid rendering when the primary query is used, if marked as dynamic to avoid overhead.

Comment by Roman Kovařík [ 14/Jun/17 ]

At the initial request in the browser, all components are rendered and cached, then the second request(if CachePolicyResult.useCache = true) again renders the same components marked as dymanic and this is a problem.

You can set skipRendering on the fragment injection listener:
https://documentation.magnolia-cms.com/display/DOCS/Advanced+Cache+Dynamic+Page+Caching#AdvancedCacheDynamicPageCaching-Fragmentinjectionlistener
and then forceUriRequest=true on the InjectUriRule
https://documentation.magnolia-cms.com/display/DOCS/SiteMesh+module#SiteMeshmodule-Rules&Tags

Comment by Vyacheslav Maksimov [ 14/Jun/17 ]

Thank you, I think this decision is appropriate.

Generated at Sun Feb 11 23:10:55 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.