[SOLVED] No caching for calculated date

Hi everybody,

I need the current month or the next month to show.
I make this with a condition.
The result is right but in FLOW_CONTEXT Production Mode there is no change, when condition change.

prototype(Vendor.Site:Presentation.Offercard) < prototype(Neos.Fusion:Component) {


    offermonth = Neos.Fusion:Case {
           if {
                condition = ${Date.dayOfMonth(Date.now()) <= 10}  // Regel soll nur greifen, wenn Monatsanfang vom 1. bis 10.
                aktmonth = ${Date.now()} // Setze aktuellen Monat.
                aktmonthf = ${Date.format(this.aktmonth, 'm')}
                renderer = ${this.aktmonthf}
               else {
                    condition = ${Date.dayOfMonth(Date.now()) > 10 && Date.month(Date.now()) < 12} // Diese Regel soll greifen ab dem 11. des Monats, sofern nicht Dezember
                    nextmonth = ${Date.create('first day of next month')}
                    nextmonthf  = ${Date.format(this.nextmonth, 'm')}
                    renderer = ${this.nextmonthf}

I suspect that the variable “offermonth” must be exempt from caching. But how should the line @cache.mode = ‘uncached’ be entered?

Nothing I’ve tried yet works.

Thanks in advance

Hi Bernd,

welcome to Neos!

You cannot really exclude a single variable from cache.
You could however set the cache lifetime for this element to one day (or lower) so it gets refreshed regularly. Even better I guess would be to calculate this in the frontend via JS to avoid removing the cache that often.

1 Like

Hi Christian,

It is enough if the cache is emptied once on the 11th of each month. That doesn’t really work, does it?

Hi Bernd,

you can calculate the time until the next 11th and set this as the cachelifetime.

See: Caching - Rendering - Manual - Guide - Neos Docs


I use the maximumLifeTime in the @cache configuration in the page footer which has a copyright notice with the current year - which has to automatically update on new years eve:

maximumLifetime = ${Date.create('first day of next year').timestamp - Date.now().timestamp}

You can alter that for the 11th of each month. It should be something like this…

maximumLifetime = ${Date.add(Date.create('first day of next month'), '11 days').timestamp - Date.now().timestamp}

You can find the docs for the Date object in the Eel Helpers Reference — Neos CMS 8.3.x documentation.

1 Like

Hi Björn,

That’s great!
I need this in my footer too.
I hadn’t thought about caching until now.
But now I was wondering how it worked for me that the year updated even though I had no longer touched an older neos project.
And in fact, now that I’ve checked I see that it still says 2022 in the footer. Oh man! :exploding_head:

After a lot of trying, I patched together the following:

    maxcachelifetime1 = ${Date.diff(Date.create('today'), Date.create('first day of next month'))}
    maxcachelifetime = ${(this.maxcachelifetime1.d * 86400) + 950400}

I like your code (Especially the extension of the timestamp) and will try it.
Thank you for the concrete solution. I like copy and paste :smile:
(But before that I didn’t spare myself from working out a solution myself)

Best regards,