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_SIZEis 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
tilesfolder is removed. - default_
dir - The platform cache directory for basemapper.
- dir
- The cache directory, or
Nonewhen 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 withNone. - set_
max_ size - Set the cache’s size limit in bytes, and trim the cache to it.