Caching
To use cache, the only option you need to set is cache=true
:
https://api.screenshotone.com/screenshot?url=https://example.com&cache=true
And the screenshot will be cached for 4 hours by default or if you specify the cache_ttl
option in seconds, you can prolong the cache time up to one month.
Caching is available for all rendering methods.
When to use cache
The best usage of cache is to make rendering less expensive and faster, in case if you plan to render a lot of similar websites.
Cache key
Screenshots are cached by the combination of all specified request options. And the cache_key option allows having different cached versions of the same screenshot.
Impact on rendering quota
Cached screenshots are not counted by quota and are not logged anywhere. They are served directly from the cache. Screenshots are cached in a combination of Cloudflare CDN and R2 storage (like Amazon S3).
However, rarely but cache misses might happen and screenshots might be rendered again and counted towards your quota.
Cache URL
There is a header x-screenshotone-cache-url
that provides a direct link to the cached image, PDF or video. The file exist as long as it was defined in the cache_ttl parameter when API request was performed with cache=true
.
And if the response_type
option is specified as json
, you can find a cache URL in the JSON response too:
{ "cache_url": "https://cache.screenshotone.com/..."}
What is the benefits of using the cache URL?
- You don’t share API keys and don’t complicate your code with signed links.
- You control when to regenerate the cache, but a user with a link to the screenshot can’t regenerate it. Because if you shared a link to an API request, once the cache is expired, it would be regenerated.
Support
In case if you have any issues with caching or any ideas on how to improve it and make it better, please contact us at support@screenshotone.com.