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

bug: cache actually not working #663

Closed
aruku7230 opened this issue Jul 15, 2018 · 3 comments
Closed

bug: cache actually not working #663

aruku7230 opened this issue Jul 15, 2018 · 3 comments

Comments

@aruku7230
Copy link
Contributor

When parsing a template with the same tags second time, because of cache, it should return the cached tokens.

test code:

  describe('when parsing a template with the same tags second time, return the cached tokens', function () {
    it('returns the same tokens for the latter parse', function () {
      var template = '{{foo}}[bar]';
      var parsedResult1 = Mustache.parse(template);
      var parsedResult2 = Mustache.parse(template);

      assert.deepEqual(parsedResult1, parsedResult2);
      assert.ok(parsedResult1 === parsedResult2);
    });
  });

test code failed on assert.ok(parsedResult1 === parsedResult2);

@aruku7230
Copy link
Contributor Author

aruku7230 commented Jul 15, 2018

The problem code may be in Writer.prototype.parse:

  Writer.prototype.parse = function parse (template, tags) {
    var cache = this.cache;
    var tokens = cache[template];

    if (tokens == null)
      tokens = cache[template + ':' + (tags || mustache.tags).join(':')] = parseTemplate(template, tags);

    return tokens;
};

The problem is the used cache key is different between the time set a cache and the time try to get a cache.

  • When set a cache, the used cache key is template
  • When try to get a cache, the used cache key is template + ':' + (tags || mustache.tags).join(':')

@raymond-lam
Copy link
Contributor

raymond-lam commented Jul 15, 2018 via email

@aruku7230
Copy link
Contributor Author

No rush. Actually, I'm also writing a PR to fix it.

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

No branches or pull requests

2 participants