mustache.js v4.0.0 Release Notes

Release Date: 2020-01-16 // over 4 years ago
  • Majority of using projects don't have to worry by this being a new major version.

    TLDR; if your project manipulates Writer.prototype.parse | Writer.cache directly or uses .to_html(), you probably have to change that code.

    ๐Ÿš€ This release allows the internal template cache to be customised, either by disabling it completely ๐Ÿ“œ or provide a custom strategy deciding how the cache should behave when mustache.js parses templates.

    const mustache = require('mustache');
    
    // disable caching
    Mustache.templateCache = undefined;
    
    // or use a built-in Map in modern environments
    Mustache.templateCache = new Map();
    

    Projects that wanted to customise the caching behaviour in earlier versions of mustache.js were forced to ๐Ÿ“œ override internal method responsible for parsing templates; Writer.prototype.parse. In short, that was unfortunate because there is more than caching happening in that method.

    We've improved that now by introducing a first class API that only affects template caching.

    0๏ธโƒฃ The default template cache behaves as before and is still compatible with older JavaScript environments. For those who wants to provide a custom more sopisiticated caching strategy, one can do that with an object that adheres to the following requirements:

    {
      set(cacheKey: string, value: string): void
      get(cacheKey: string): string | undefined
      clear(): void
    }
    

    โž• Added

    • [#731]: Allow template caching to be customised, by [@AndrewLeedham].

    โœ‚ Removed

    • ๐Ÿšš [#735]: Remove .to_html(), by [@phillipj].