Problem/Motivation

Currently, the block is not cached at all. That means for every visitor it is re-rendered all the time. Now this makes sense if someone displays a precise date with minutes and seconds. But for sites which display only the current day and name day, this repeating database call is unnecessary.

Steps to reproduce

Proposed resolution

Find a way to set the caching for the block on the settings form. And make it invalidate itself after the needed period of time:
- If the displayed date format contains the current year, month or day, then cache it until midnight:

  $cacheMaxAge = strtotime('tomorrow') - time();

- If the displayed date format contains the hour, then cache it until the next hour:

  $start = date("H:i:s");
  $end = date("H:00:00",strtotime("$start +1 hour"));
  $cacheMaxAge = (strtotime($end) - strtotime($start));

- If the displayed date format contains the minute, then cache until the next minute:

  $start=date("H:i:s");
  $end=date("H:i:00", strtotime("$start +1 minute"));
  $cacheMaxAge = (strtotime($end) - strtotime($start));

- If the displayed date format contains seconds or milliseconds, then I suggest omitting the cache. And warn the user that it could have an affect on the site's performance.
- Also, when changing the settings, invalidate the cached block.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

kaszarobert created an issue. See original summary.

kaszarobert’s picture

Status: Active » Needs review
StatusFileSize
new3.79 KB

I attach a patch with the requested feature. After applying the patch, drush cr (cache rebuild) is needed if the block is actually used.

sajt’s picture

Hello!

I added you as maintainer to this module. Please feel freeto make any changes :)

Hajrá!

  • kaszarobert committed 54a99aa on 8.x-1.x
    Issue #3229448 by kaszarobert: Caching the Nameday block
    
kaszarobert’s picture

Category: Bug report » Feature request
Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.