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_TOKENThe 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"// storyblok-js-client@>=7, node@>=18import Storyblok from "storyblok-js-client";
const storyblok = new Storyblok({ accessToken: "krcV6QGxWORpYLUWt12xKQtt",});
try { const response = await storyblok.get('cdn/spaces/me', {}) 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()let storyblok = URLSession(storyblok: .cdn(accessToken: "wANpEQEsMYGOwLxwXQ76Ggtt"))let request = URLRequest(storyblok: storyblok, path: "spaces/me")let (data, _) = try await storyblok.data(for: request)print(try JSONSerialization.jsonObject(with: data))val client = HttpClient { install(Storyblok(CDN)) { accessToken = "wANpEQEsMYGOwLxwXQ76Ggtt" }}
val response = client.get("spaces/me")
println(response.body<JsonElement>()){ "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"// storyblok-js-client@>=7, node@>=18import Storyblok from "storyblok-js-client";
const storyblok = new Storyblok({ accessToken: "krcV6QGxWORpYLUWt12xKQtt",});
try { const response = await storyblok.get('cdn/stories', { "cv": "1541863983"}) 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"}})let storyblok = URLSession(storyblok: .cdn(accessToken: "wANpEQEsMYGOwLxwXQ76Ggtt"))var request = URLRequest(storyblok: storyblok, path: "stories")request.url!.append(queryItems: [ URLQueryItem(name: "cv", value: "1541863983")])let (data, _) = try await storyblok.data(for: request)print(try JSONSerialization.jsonObject(with: data))val client = HttpClient { install(Storyblok(CDN)) { accessToken = "wANpEQEsMYGOwLxwXQ76Ggtt" }}
val response = client.get("stories") { url { parameters.append("cv", "1541863983") }}
println(response.body<JsonElement>())Was this page helpful?
This site uses reCAPTCHA and Google's Privacy Policy (opens in a new window) . Terms of Service (opens in a new window) apply.
Get in touch with the Storyblok community