esmero / format_strawberryfield

Set of Display formatters, extractors and utils to make Strawberry field data glow
GNU Lesser General Public License v3.0
6 stars 9 forks source link

ISSUE-412: Tested on production. Finally IP embargoes can cut the Cache crap #413

Closed DiegoPino closed 4 months ago

DiegoPino commented 5 months ago

see #412

This pull makes something wonderful. Embargoes are still resolved per Entity. (and I can do better I know and will) on each SBF formatter call/exposed endpoint etc. But the response is statically cached and accumulated during an HTTP request (means 10 fields == 1 calculation). We still kill the page cache & dynamic cache if there is an IP embargo for an object (even if resolves to not embargoed bc there is no context/saved data in Drupal I can use to differentiate on Anonymous from another, all comes in the request itself), but also (to make Drupal's weirdness/lack of consistency) happy, just after the View Mode/Display (ignoring the internal render array elements) decides to cache everything, we make the cache time to live == 0 for the whole Node. And bum. It works.

How to test this works.

Add to an embargoed object the proper IP allowanced metadata and on the same Object, in the Description template add this:

{{ "now"|date("F jS \\a\\t g:ia") }}

Notice that if accessing the ADO as an anonymous, the time will be changing/dynamically. If accessing the same ADO as an admin the last time it was cached it will stay fixed (reload see how nothing changes). Same for Objects (anonymous and not) that have no embargo. Cached once, served from there on.

Anyhow. I need a life