New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache validation #44

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

Comments

Projects
None yet
2 participants
@MatTheCat

MatTheCat commented Dec 28, 2016

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

This comment has been minimized.

Show comment
Hide comment
@pmjones

pmjones Dec 28, 2016

Owner

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?

Owner

pmjones commented Dec 28, 2016

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

This comment has been minimized.

Show comment
Hide comment
@MatTheCat

MatTheCat Dec 28, 2016

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

MatTheCat commented Dec 28, 2016

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

@pmjones

This comment has been minimized.

Show comment
Hide comment
@pmjones

pmjones Dec 28, 2016

Owner

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.

Owner

pmjones commented Dec 28, 2016

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

This comment has been minimized.

Show comment
Hide comment
@MatTheCat

MatTheCat Dec 28, 2016

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

MatTheCat commented Dec 28, 2016

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

@pmjones

This comment has been minimized.

Show comment
Hide comment
@pmjones

pmjones Dec 28, 2016

Owner

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?

Owner

pmjones commented Dec 28, 2016

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

This comment has been minimized.

Show comment
Hide comment
@MatTheCat

MatTheCat Dec 28, 2016

Yep thanks I'll try implementing this!

MatTheCat commented Dec 28, 2016

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