Skip to content
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

Caching and caching tests improvements #1808

Merged
merged 6 commits into from Jan 13, 2015
Merged

Caching and caching tests improvements #1808

merged 6 commits into from Jan 13, 2015

Conversation

@TimothyGu
Copy link
Member

@TimothyGu TimothyGu commented Jan 3, 2015

No description provided.

TimothyGu added 5 commits Jan 2, 2015
It is already covered by some other tests, but not directly, resulting
in an uncovered branch.

Places already covering this function:

1. Deprecation test for `options.client` (under-the-hood)
2. All the test cases
@TimothyGu
Copy link
Member Author

@TimothyGu TimothyGu commented Jan 11, 2015

I'll merge this in two days if no one reviews, to keep PRs from rotting.

@ForbesLindesay
Copy link
Member

@ForbesLindesay ForbesLindesay commented Jan 12, 2015

If we did,handleSrcCache as:

function handleFileCache (options) {
  if (options.cache && exports.cache[options.filename]) {
    return exports.cache[options.filename];
  } else {
    var result = exports.compile(fs.readFileSync(options.filename, 'utf8'), options);
    if (options.cache) exports.cache[options.filename] = result;
    return result;
  }
}

We could skip the extra (totally pointless) cache of the source strings.

@vendethiel
Copy link
Contributor

@vendethiel vendethiel commented Jan 12, 2015

(2nd if's condition should read options.cache)

@ForbesLindesay
Copy link
Member

@ForbesLindesay ForbesLindesay commented Jan 12, 2015

Thanks, updated

@TimothyGu
Copy link
Member Author

@TimothyGu TimothyGu commented Jan 12, 2015

IIRC I tried that but it didn't work for some obscure reason I do not recall right now. Will get back to you.

@TimothyGu
Copy link
Member Author

@TimothyGu TimothyGu commented Jan 12, 2015

Updated PR. Removed handleSrcCache() altogether.

? exports.cache[key] || (exports.cache[key] = fs.readFileSync(path, 'utf8'))
: fs.readFileSync(path, 'utf8');
return exports.render(str, options);
return exports.render(null, options);

This comment has been minimized.

@ForbesLindesay

ForbesLindesay Jan 12, 2015
Member

Maybe it would be better if this did:

return handleTemplateCache(options)(options);

It's not much duplicated code, and it keeps exports.render from needing to accept null for the string. We could then add a check in exports.render that throws if str === null to catch that odd corner case. I'd hate to end up having to support it forever.

This comment has been minimized.

@TimothyGu

TimothyGu Jan 12, 2015
Author Member

True.

@TimothyGu TimothyGu force-pushed the caching-test branch from b2fc998 to 781901a Jan 12, 2015
ForbesLindesay added a commit that referenced this pull request Jan 13, 2015
Caching and caching tests improvements
@ForbesLindesay ForbesLindesay merged commit d63928a into master Jan 13, 2015
1 check passed
1 check passed
@TimothyGu
continuous-integration/travis-ci The Travis CI build passed
Details
@ForbesLindesay ForbesLindesay deleted the caching-test branch Jan 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants