Overview
The cache system stores IANA bootstrap registry files locally to reduce network requests and improve performance. Cached files are automatically invalidated after a configurable TTL (time-to-live).Cache
Bootstrap cache manager.new()
Creates a new cache instance.- Cache directory:
~/.cache/rdap/on all platforms (determined by$HOMEenvironment variable) - Default TTL: 24 hours (86400 seconds)
Cache instance
with_ttl()
Sets a custom cache TTL.Time-to-live for cached files
Cache instance with updated TTL
Example:
get()
Retrieves a cached file if valid.Cache key (filename)
None if:
- File doesn’t exist
- File has expired (modification time + TTL < current time)
- File cannot be read
set()
Saves data to cache.Cache key (filename)
Data to cache
~/.cache/rdap/{key}. The file’s modification time is used for TTL calculation.
clear()
Clears all cached files.Cache Directory
The cache directory is determined by the$HOME environment variable:
- Path:
~/.cache/rdap/ - Platform: Same location on Linux, macOS, and Windows (via WSL)
- Auto-created: Directory is created automatically if it doesn’t exist
Typical Cached Files
The cache directory typically contains:Cache Invalidation
Cache invalidation is based on file modification time:Automatic Invalidation
Whenget() is called:
- Check if file exists
- Read file metadata to get modification time
- Calculate elapsed time since modification
- If elapsed > TTL:
- Delete the file
- Return
None
- Otherwise, return file contents
Manual Invalidation
Useclear() to force invalidation of all cached files:
Caching Behavior
Default TTL
The default TTL is 24 hours (86400 seconds). This balances:- Performance: Reduces network requests for frequently-used bootstrap registries
- Freshness: Ensures IANA updates are picked up within a day
Custom TTL
Customize TTL based on your use case:Cache Miss Handling
Whenget() returns None, the bootstrap client fetches the registry from IANA and caches it with set():
Configuration Integration
The cache TTL can be configured viaconfig.json:
Example Usage
Basic Caching
Custom TTL
Cache Management
Error Handling
Cache operations can fail due to:- I/O errors: Permission issues, disk full, etc.
- Directory creation: Unable to create
~/.cache/rdap/ - File operations: Unable to read/write cache files
Result<T> and should be handled appropriately:
Related
- Configuration API - Cache TTL configuration
- Bootstrap API - Bootstrap registry fetching and caching
