# 9.1 Cache

► |  | Pollen: the book is a program

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

▼ | 9 | Module reference

9.1 | Cache
9.2 | Decode
9.3 | File
9.4 | Pagetree
9.5 | Render
9.6 | Template
9.7 | Tag
9.8 | Top
9.9 | World

On this page:

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

6.0.1
top ← prev up next →

#### 9.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.
top ← prev up next →