Contentful logo

Contentful Community

I don't understand the caching, can someone please explain


I am building a pure frontend application useíng React and contentful.js. But my problem is that for some reason, our application makes a lot of request to the CDN API. Looking right now, we have already made over 335,000 requests in only three days. I need to look into why we are making so many requests.

I saw this text: “There are no limits enforced on requests that hit our CDN cache, i.e. the request doesn’t count towards your rate limit and you can make an unlimited amount of cache hits.” But I don’t understand what is meant with the “CDN cache”. Is that something I need to turn on? Or do I need to implement that myself?

I hope you don’t find this question stupid and may be able to help me understand this.

Best regards

CDN cache is a proxy between your app and Contentful backend. It’s managed by Contentful and is always “turned on” for everybody who calls the API. When you make a request to the CDA, you should get a x-cache response header, which says whether the request HIT or MISS the cache.

An additional note is that we do have a lot of users accessing the system, so the large number of requests is explained by that.

But I still don’t understand the cache, since it’s a pure frontend app, will it not cache each request?

Regards /Martin

I’m not sure if I understand your question. :thinking: When your pure frontend app calls Contentful API, the response is cached. The caching is done by Contentful, you don’t need to do anything about it. Next time your app makes same request again, it will get the cached response. Getting cached response is faster than uncached and doesn’t count towards rate limits.

If you wonder why not all requests are cache HIT, then it’s because cache gets invalidated when your content changes in Contentful and also after a timeout period.