14 Module reference
14.1 Cache
14.2 Core
14.3 Decode
14.4 File
14.5 Pagetree
14.6 Render
14.7 Setup
14.8 Tag
14.9 Template
14.10 Top
On this page:
14.1.1 Preloading and reseting
14.1.2 Disabling the cache
14.1.3 Scope of dependency tracking
14.1.4 Functions
cached-doc
cached-metas
reset-cache
6.3.90.900

14.1 Cache

 (require pollen/cache) package: pollen

The slowest part of a Pollen render is compiling a source file. Because Pollen allows source files to be edited and previewed dynamically, these files get recompiled a lot. Therefore, Pollen stores copies of the exports of source files — namely, whatever is stored in doc and metas — in a cache so they can be reused.

In each directory of your project, Pollen creates a subdirectory called "pollen-cache". The files are stored on disk so they can be reused between sessions. If you delete files within a cache directory (or the whole thing), don’t worry — everything will get regenerated. (However, you should not read or write to any "pollen-cache" directory, as the implementation details are subject to change.)

14.1.1 Preloading and reseting

Though the cache will be populated as you use Pollen, you can also preheat it with raco pollen setup. This command will load all your source files into the cache. This will give you the snappiest performance during an interactive session with the project server.

If you want to reset all the compile caches, use raco pollen reset.

14.1.2 Disabling the cache

The compile cache is controlled by the overridable value setup:compile-cache-active. Thus, to disable the compile cache, add a setup submodule to your "pollen.rkt" like so:

(module setup racket/base
  (provide (all-defined-out))
  (define compile-cache-active #f))

Pollen also caches rendered output files, so if you want to disable all caching — thus forcing everything to recompile, every time — you should also disable the render cache by overriding setup:render-cache-active:

(module setup racket/base
  (provide (all-defined-out))
  (define compile-cache-active #f)
  (define render-cache-active #f))

Be warned that this will make your rendering much slower. But you will be guaranteed an entirely fresh recompile each time, which can sometimes be useful in development.

14.1.3 Scope of dependency tracking

The compile cache tracks the modification date of the source file, the current setting of The POLLEN environment variable, and the modification dates of the template and "pollen.rkt" (if they exist).

It does not, however, track every possible dependency. So in a complex project, it’s possible to create deep dependencies that aren’t noticed by the cache.

Unfortunately, there’s no way around this problem. For the cache to be useful, there has to be a limit on the horizon of dependency checking. To capture every possible dependency, the cache would have to recompile every file, every time — which would be equivalent to not caching at all.

Those who need that kind of deep dynamism can disable the cache.

14.1.4 Functions

procedure

(cached-doc source-path)  txexpr?

  source-path : pathish?

procedure

(cached-metas source-path)  hash-eq?

  source-path : pathish?
Try to retrieve the requested value out of the cache. If it’s not there, or out of date, dynamic-require is used to update it from the source.

Despite their names, these functions actually rely on setup:main-export and setup:meta-export (which default to doc and metas). Thus, if you override those names, everything will still work as expected.

If you want the speed benefit of the cache, you should always use cached-doc and cached-metas to get data from Pollen source files. That doesn’t mean you can’t also use functions like require, local-require, and dynamic-require. They’ll just be slower.

procedure

(reset-cache)  void?

Clears the cache. When only the nuclear option will do.