Drupal 8:
I have code for a block that successfully does its job and returns it. The block is called "RacerProfile", and it passes all its content to the variable "$ pageContent". At the very end, it returns #markup. OK. Now, how can I say that this is not valid every six hours?
class RacerProfile extends BlockBase { public function build() {
In other Drupal answers, I saw that "D8 has tags and cache contexts that will automatically change the value of a block if something changes." Great, but my code is checking the second database. Drupal has no way of knowing what's going on there. (Without verification, obviously.) So, how do I add cache tags with the specified timeouts? (Or do cache tags even do this?) I cannot find examples.
Notes:
- the above code does not give the desired result. The page is static for anonymous users. It changes only when the user / admin clears the cache through the web admin.
-Obviously, this does not apply to increasing the maximum cache in the administration area Configuration> Performance> Caching> Maximum cache cache age. I do not want this to apply to the entire site, only to this block. In addition, this setting does not seem to control this aspect of caching in any way, but instead is cache information that is screwed into the header of the displayed pages.
-Obviously, this has nothing to do with settings.php parameters, since again I do not want this to apply to the entire site, and different modules will have different timeout requirements.
- The traffic for the site is relatively low, so if you visualize a thing four times a day, even this needs to be done only once a day, this is not a problem. Every six hours, this means that it has changed before people wake up in four time zones. Basically .;) I directly declare here that I am interested in this work in general, before I worry about optimizing the download or use.
- I have several custom blocks with different expiration periods.
- Of course, I have a lot of problems with Google, and you still have to find examples that indicate a specific (measured in unit time) timeout for the module. Even in the D8 module examples on drupal.org
- Namely, the block should have its cache control for anonymous users. People without accounts, the "public" browses the site.