Skip to content

cache

@vuepress/plugin-cache

This plugin is used to solve the issue of long startup times in VuePress.

By caching the markdown render during the initial startup of the VuePress development server, the plugin skips unnecessary markdown render on subsequent startups, thus speeding up the startup process.

The cached render is keyed by the page content, the frontmatter that the configuration passes to the page (the frontmatter of the Markdown file is part of the page content), the site base, the Markdown options, the names and the order of the plugins, and the dev/build mode. Changing any of them invalidates the cache.

The key keeps a function by its source and a BigInt by its digits, so a changed function body or a changed integer invalidates the cache. Other values are compared the way JSON compares them, so two values that JSON cannot tell apart, such as a RegExp and an empty object, share a key. A page whose configuration cannot be fingerprinted at all is rendered on every run instead of being cached. Writing the cache is best effort: a page whose env still cannot be serialized by JSON, a BigInt in the frontmatter for example, is rendered normally but is not written to the cache.

Content read at render time

The key cannot see everything a plugin reads while rendering. Files that other plugins import or include at render time, and settings that a plugin writes into the Markdown parser itself, are not part of it. When you change such a file or setting, delete the .vuepress/.cache directory to start from a clean cache.

Usage

npm i -D @vuepress/plugin-cache@next

Using it as last plugin

It is recommended to place cachePlugin as the last item in the plugins configuration, as this can ensure maximum utilization of caching.

.vuepress/config.ts
import { cachePlugin } from '@vuepress/plugin-cache'

export default {
  plugins: [
    // ... other plugins

    // using as the last plugin
    cachePlugin({
      // options
    }),
  ],
}

Options

type'filesystem' | 'memory'
Default'memory'

Cache type.

  • 'memory': Use memory cache. It can achieve optimal optimization effects, but as the project scales up, it occupies more memory, suitable for projects with fewer pages.
  • 'filesystem': Use file system cache, for complex projects with many pages, it is recommended.
enableInCIboolean

Whether to enable the cache in CI environment.

In most cases, the cache plugin could slow down the speed in CI.

enableInCiDeprecatedboolean

Deprecated, use enableInCI instead.

MIT Licensed