Skip to content
This repository has been archived by the owner on Oct 6, 2020. It is now read-only.

Fix issues when the initial (cached) request is json #4

Closed
wants to merge 5 commits into from

Conversation

cpacey
Copy link

@cpacey cpacey commented Mar 8, 2016

We JSON.parse and JSON.stringify the cached results as necessary.

Fixes #3.

Carl Pacey added 2 commits March 8, 2016 16:37
If subsequent requests want json output (options.json = true), then we try
to JSON.parse() the cached content, which is already json, which throws.
This causes the cache lookup to fail, so we go get from source again.

If subsequent requests don't want json output, then we successfully serve
from the cache, but the cached content is json, rather than the expected
string content.
We JSON.parse and JSON.stringify the cached results as necessary.
var parsed = JSON.parse(cachedContent.body);
var parsed;
if( typeof cachedContent.body === 'object' ) {
parsed = cachedContent.body;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to return a deep clone, otherwise client changes to the object would bleed between requests.

Carl Pacey added 3 commits March 9, 2016 09:44
Previously, if any request handler modified a json response, then that
modification would remain in the cache and be incorrectly returned in
subsequent requests.

With this change, we deep clone cached objects so each request handler gets
its own copy of the original response.
@cpacey cpacey closed this Feb 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant