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

No description provided.

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

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

@ForbesLindesay
Copy link
Member

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

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

@ForbesLindesay
Copy link
Member

Thanks, updated

@TimothyGu
Copy link
Member Author

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

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);
Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

True.

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
@ForbesLindesay ForbesLindesay deleted the caching-test branch January 13, 2015 03:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants