[SOLVED] Inline Editing Caching Problem


(Christian Foidl) #1

Hi!

I am currently working on a NEOS site where I need to output some nodes on a page that are stored on other pages.

For example if I want to output the first headline found in the site node of my page, I would define the following in the page’s fusion template:

prototype(Some.Package:Page) < prototype(Neos.Neos:Page) {
    body {
        templatePath = 'resource://Some.Package/Private/Templates/Page/Page.html'
        sectionName = 'body'

        firstHeadline = ${q(site).find('[instanceof Some.Package:Headline]').first().get(0)}
    }
}

Page.html template:

{namespace neos=Neos\Neos\ViewHelpers}

<f:section name="body">
    <f:render section="headline" arguments="{headline: firstHeadline, title: firstHeadline.properties.title}" />
</f:section>

<f:section name="headline">
    <neos:contentElement.wrap node="{headline}">
        {neos:contentElement.editable(property: 'title')}
    </neos:contentElement.wrap>
</f:section>

Let’s pretend the first headline found is stored at the page /sites/home/subpage-1 and we want to render it on the page /sites/home/subpage-1/subpage-2.

With the templates above, the headline from subpage-1 is rendered on subpage-2 and can be inline edited.

The problem is that when editing the headline on subpage-2 the node value for the title property is changed on the headline itself, which is stored on subpage-1, but when subpage-2 is reloaded in the backend, the old value of the headline is displayed.

The only way I have found to update the headline value on subpage-2 is via a full cache clear.

Is this a bug in NEOS, or is my implementation wrong?
Thanks in adavance!


(Christian Foidl) #2

I just found the solution myself.

The problem has nothing to do with the inline editing itself.
The value of the headline in subpage-2 was not even updated when chaning the headline in subpage-1 directly. As I already mentioned in the first post, the problem had something to do with the caching of subpage-2

To solve this problem, the cache of subpage-2 (or rather the prototype of subpage-2) has to be explicitly configured to invalidate when the found headline changes.

Updated fusion template:

prototype(Some.Package:Page) < prototype(Neos.Neos:Page) {
    @context.firstHeadline = ${q(site).find('[instanceof Garger.DerHirschenAt:Headline]').first().get(0)}

    body {
        templatePath = 'resource://Some.Package/Private/Templates/Page/Page.html'
        sectionName = 'body'

        firstHeadline = ${firstHeadline}
    }

    @cache {
        entryTags {
            firstHeadline = ${Neos.Caching.nodeTag(firstHeadline)}
        }
    }
}

By defining firstHeadline = ${Neos.Caching.nodeTag(firstHeadline)} in the cache configuration, we tell Neos to clear the cache of the page whenever the firstHeadline changes.

More about caching in Neos: https://neos.readthedocs.io/en/stable/CreatingASite/ContentCache.html#cache-entry-tags


(Sebastian Kurfuerst) #3

Hey Christian,

Great that you found the solution to your problem, and even better that you documented it so nicely here :heart: :smile:

Don’t hesitate to ask further questions :slight_smile:

All the best,
Sebastian