Join GitHub today
Cache validation #44
Great question. Let's try to work through it.
Quoting Infoglactic: "304 Not Modified Indicates that the resource has not been modified since the version specified by the request headers If-Modified-Since or If-None-Match. In such case, there is no need to retransmit the resource since the client still has a previously-downloaded copy." https://infogalactic.com/info/List_of_HTTP_status_codes#3xx_Redirection
So the question becomes, how does your application know the resource has not been modified?
Stick with me. :-)
Sure -- you touch a form of storage. Or, if you don't happen to have APCU or memcache or something else, you would read a little bit from the database to see if the resource had been modified.
So then the question becomes: why is your user interface layer (the part that reads input from a request, and writes output to a response) touching storage at all? It's user-interface, not infrastructure or domain.
One of the rules-of-thumb in ADR is: "if it touches storage, it probably goes in the Domain."
And that's the answer here. Your action would pass along the "has it changed?" headers to the domain (as part of the user input). The domain would use those as part of its work to return a payload; if the resource has not changed, the payload might be empty with a status of "NOT_MODIFIED". The action would then pass the payload to a responder; if the payload status was NOT_MODIFIED, the responder would send back a 304.
Correct. The Domain is what interacts with all the infrastructure bits, maybe in a DDD sort of way, or maybe in some other way. (As a side note, it's not so much "needed to generate a response" as "needed to deliver a result/payload back to the action" -- but that might be nitpicking. ;-)
Does that help?