Cache validation #44

Closed
MatTheCat opened this Issue Dec 28, 2016 · 6 comments

Projects

None yet

2 participants

@MatTheCat

If the responder is in charge of building the response from the return of an action how do you handle returning a 304? It should be happening before the end of the action but it still would be a response.

@pmjones
Owner
pmjones commented Dec 28, 2016 edited

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?

@MatTheCat

I fail to see how this is related? You could store in apcu the time the last subresource has been modified eg.

@pmjones
Owner
pmjones commented Dec 28, 2016 edited

I fail to see how this is related?

Stick with me. :-)

You could store in apcu the time the last subresource has been modified eg.

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.

@MatTheCat

Oh okay I see the point. So it's no problem the domain knows all of the resources needed to generate a response?

@pmjones
Owner
pmjones commented Dec 28, 2016 edited

So it's no problem the domain knows all of the resources needed to generate a response?

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?

@MatTheCat

Yep thanks I'll try implementing this!

@MatTheCat MatTheCat closed this Dec 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment