► |  | Pollen: the book is a program

1 | Installation
2 | Quick tour
3 | Backstory
4 | The big picture
5 | First tutorial
6 | Second tutorial
7 | Third tutorial
8 | Using raco pollen
9 | File formats
10 | ◊ command overview
11 | Module reference
12 | Acknowledgments
13 | License & source code
| Index

▼ | 11 | Module reference

11.1 | Cache
11.2 | Decode
11.3 | File
11.4 | Pagetree
11.5 | Render
11.6 | Template
11.7 | Tag
11.8 | Top
11.9 | World

On this page:

current-cache
cached-require
make-cache
reset-cache
cache-ref

6.1.0.8
← prev up next →

#### 11.1`` Cache

(require pollen/cache) | package: pollen

The slowest part of a render is parsing and decoding the source file. Often, previewing a single source file necessarily means decoding others (for instance templates, or other source files that are linked into the main source file). But usually, only one source file is changing at a time. Therefore, Pollen stores copies of the exports of source files — namely, whatever is stored in doc and metas — in the cache so they can be reused.

> parameter (current-cache) → hash?
> (current-cache hash) → void?
> hash : hash?

A parameter that refers to the current cache. It is initialized with make-cache.

The cache is a hash table that uses the complete path of a source file as its keys. The value associated with each of these keys is a subcache — another hash table with keys 'doc, 'metas (for storing the exports of the source file) and 'mod-time (for storing the modification time, provided by file-or-directory-modify-seconds).

> procedure (cached-require source-path key) → (or/c txexpr? hash? integer?)
> source-path : pathish?
> key : (or/c 'doc 'metas 'mod-time)

Similar to (dynamic-require source-path key), except that it first tries to retrieve the requested value out of current-cache. If it’s not there, or out of date, dynamic-require is used to update the value.

The only keys supported are 'doc, 'metas, and 'mod-time.

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

> procedure (make-cache) → hash?

Initializes current-cache.

> procedure (reset-cache) → void?

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

> procedure (cache-ref source-path) → hash?
> source-path : pathish?

Returns the subcache associated with the key source-path, which will itself be a hash table. See current-cache.
← prev up next →