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
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | nameday-3229448-02-block-caching.patch | 3.79 KB | kaszarobert |
Comments
Comment #2
kaszarobertI attach a patch with the requested feature. After applying the patch, drush cr (cache rebuild) is needed if the block is actually used.
Comment #3
sajt commentedHello!
I added you as maintainer to this module. Please feel freeto make any changes :)
Hajrá!
Comment #5
kaszarobert