Skip to main content

Module cache

Module cache 

Source
Expand description

A disk cache for map tiles, so repeated renders of an area do not fetch the same tiles again (tile usage policies such as OpenStreetMap’s ask clients to cache).

Tiles are kept for as long as the server’s Cache-Control: max-age or Expires allows (a day when it says nothing), and never when it sends no-store or no-cache. Tiles fetched with an Authorization header and tiles from the local machine are not cached.

The cache lives in BASEMAPPER_CACHE_DIR when that is set (off disables it), else in the platform cache directory (%LOCALAPPDATA%, ~/Library/Caches, $XDG_CACHE_HOME or ~/.cache), under basemapper (the R package uses tools::R_user_dir("basemapper", "cache"), as CRAN asks). set_dir changes it at run time.

The cache is kept small: expired tiles are deleted, and past its size limit (250 MB, or BASEMAPPER_CACHE_MAX_SIZE in MB; set_max_size) the least recently used tiles go first. This clean-up runs in the background, on the first tile stored in a session and every PRUNE_EVERY tiles after.

Structs§

Pruned
What a clean-up did.

Constants§

DEFAULT_MAX_SIZE
The size limit when BASEMAPPER_CACHE_MAX_SIZE is not set: 250 MB.
PRUNE_EVERY
Clean up after this many stored tiles (and on the first in a session).

Functions§

clear
Delete every cached tile. Only the cache’s own tiles folder is removed.
default_dir
The platform cache directory for basemapper.
dir
The cache directory, or None when caching is off.
max_size
The cache’s size limit in bytes.
prune
Delete expired tiles, then the least recently used ones until the cache is under 80% of its size limit (so clean-ups are not needed on every store). Unfinished writes older than an hour go too.
set_dir
Move the cache to dir, or turn it off with None.
set_max_size
Set the cache’s size limit in bytes, and trim the cache to it.