Caching Policy
The Basalt SDK implements a two-level caching strategy to optimize performance and ensure high availability of your prompts.Caching Architecture
Basalt employs a dual-layer caching system:- API Cache: Our backend maintains a distributed cache to ensure high availability and reliability, even during service disruptions.
- SDK Local Cache: The SDK includes a built-in local cache that stores recently retrieved prompts to minimize network requests and improve response times.
Default Behavior
By default, the SDK’s local cache is enabled with a 5-minute duration. This means:- Repeated requests for the same prompt within a 5-minute window will be served from the local cache
- After 5 minutes, the cache entry expires and a new request to the API will be made
- The API may still serve a cached response if the prompt didn’t change in the meantime
Disabling Cache
You can disable the local SDK cache for specific requests when you need the most up-to-date version of a prompt:The local cache is currently available only on the
get
method. On the method list
and describe
, the API cache is entirely managing the requests.Best Practices
Here are some recommendations for effectively using the caching system:- Production Environments: Keep caching enabled in production to maximize performance and reduce API calls.
- Development Environments: Consider disabling caching during development to ensure you’re always working with the latest prompt versions:
- Time-Sensitive Operations: Disable caching for operations where having the absolute latest version is critical.
- Burst Operations: Keep caching enabled when making many requests in a short period to avoid rate limiting.
Global Cache Configuration
You can configure global caching behavior when initializing the SDK:Cache Invalidation
The SDK automatically handles cache invalidation in the following scenarios:- When the cache duration expires (default: 5 minutes)
- When explicitly requested with
cache: false
- When using the API to update or modify prompts (the API invalidates relevant cache entries)
Benefits of Caching
Utilizing the SDK’s caching system provides several advantages:- Improved Performance: Reduced latency for frequently accessed prompts
- Reduced API Costs: Fewer API calls means lower operational costs
- Network Resilience: Ability to serve cached content during network disruptions
- Reduced Load: Less strain on your application and our API servers
When Not to Use Caching
While caching is beneficial in most scenarios, consider disabling it in these cases:- During active prompt development and testing
- For prompts that must always reflect the latest updates
- In CI/CD pipelines where reproducibility is essential