Cache Invalidation
Storyblok uses a Content Delivery Network (CDN) to deliver content as fast as possible. To have a high cache hit rate for published content, Storyblok uses a cv
parameter (cache version), which is a Unix timestamp.
The most up-to-date cv
value of a space can be retrieved with an API call excluding the cv
parameter:
https://api.storyblok.com/v2/cdn/spaces/me/?token=YOUR_TOKEN
The API response will contain a cv
value that can be used in subsequent API requests to receive the latest version of the content. In order to handle cache invalidation, the cv
value needs to be stored in memory. Furthermore, it needs to be updated when certain criteria are met. For example, Storyblok’s webhook events may be used to invalidate the cache whenever content is published, updated, or deleted.
Related resources
Section titled “Related resources”Examples
Section titled “Examples”Retrieve the latest cache version
Section titled “Retrieve the latest cache version”curl "https://api.storyblok.com/v2/cdn/spaces/me?token=wANpEQEsMYGOwLxwXQ76Ggtt"
// Using the Universal JavaScript Client:// https://github.com/storyblok/storyblok-js-clientStoryblok.get('cdn/spaces/me', {}) .then(response => { console.log(response) }).catch(error => { console.log(error) })
$client = new \Storyblok\Client('YOUR_STORYBLOK_SPACE_ACCESS_TOKEN');
$client->get('spaces/me')->getBody();
HttpResponse<String> response = Unirest.get("https://api.storyblok.com/v2/cdn/spaces/me?token=wANpEQEsMYGOwLxwXQ76Ggtt") .asString();
var client = new RestClient("https://api.storyblok.com/v2/cdn/spaces/me?token=wANpEQEsMYGOwLxwXQ76Ggtt");var request = new RestRequest(Method.GET);
IRestResponse response = client.Execute(request);
import requests
url = "https://api.storyblok.com/v2/cdn/spaces/me"
querystring = {"token":"wANpEQEsMYGOwLxwXQ76Ggtt"}
payload = ""headers = {}
response = requests.request("GET", url, data=payload, headers=headers, params=querystring)
print(response.text)
require 'storyblok'client = Storyblok::Client.new(token: 'YOUR_TOKEN')
client.space()
import Foundation
let request = NSMutableURLRequest(url: NSURL(string: "https://api.storyblok.com/v2/cdn/spaces/me?token=wANpEQEsMYGOwLxwXQ76Ggtt")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0)request.method = "GET"
let session = URLSession.sharedlet dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) }})
dataTask.resume()
{ "space": { "domain": "https://storyblok.com/", "id": 123456, "name": "Example Space", "version": 1706094649 }}
Request a specific cache version
Section titled “Request a specific cache version”curl "https://api.storyblok.com/v2/cdn/stories?cv=1541863983&token=wANpEQEsMYGOwLxwXQ76Ggtt"
// Using the Universal JavaScript Client:// https://github.com/storyblok/storyblok-js-clientStoryblok.get('cdn/stories', { "cv": "1541863983"}) .then(response => { console.log(response) }).catch(error => { console.log(error) })
$client = new \Storyblok\Client('YOUR_STORYBLOK_SPACE_ACCESS_TOKEN');
$client->getStories([ "cv" => "1541863983"])->getBody();
HttpResponse<String> response = Unirest.get("https://api.storyblok.com/v2/cdn/stories?cv=1541863983&token=wANpEQEsMYGOwLxwXQ76Ggtt") .asString();
var client = new RestClient("https://api.storyblok.com/v2/cdn/stories?cv=1541863983&token=wANpEQEsMYGOwLxwXQ76Ggtt");var request = new RestRequest(Method.GET);
IRestResponse response = client.Execute(request);
import requests
url = "https://api.storyblok.com/v2/cdn/stories"
querystring = {"cv":"1541863983","token":"wANpEQEsMYGOwLxwXQ76Ggtt"}
payload = ""headers = {}
response = requests.request("GET", url, data=payload, headers=headers, params=querystring)
print(response.text)
require 'storyblok'client = Storyblok::Client.new(token: 'YOUR_TOKEN')
client.stories({:params => { "cv" => "1541863983"}})
import Foundation
let request = NSMutableURLRequest(url: NSURL(string: "https://api.storyblok.com/v2/cdn/stories?cv=1541863983&token=wANpEQEsMYGOwLxwXQ76Ggtt")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0)request.method = "GET"
let session = URLSession.sharedlet dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) }})
dataTask.resume()
Get in touch with the Storyblok community