Choose your caching strategy
0% complete
Caching helps reduce the wait time that you and the users of your app face when your app gets content from external resources like APIs.Depending on your requirements and tolerance of stale content, make sure you choose the right caching strategy.
Cache in a nutshell
A cache is an additional layer of storage used to retrieve data in your app quickly. With Kontent.ai, the cache sits between your app and an API. The cache contains entries with responses from the API. When your app fetches content, it first checks whether the content is already in the cache. If it’s available in the cache, there’s no need to contact an API. If it’s not yet cached, your app makes an API request and stores the response in its cache. When the content is updated in Kontent.ai, the cached response needs to be invalidated. Because specific parts of your content might depend on other parts, you need to keep track of the relations among the cached responses, i.e., their dependencies. When your app invalidates a cached response, it should also invalidate any other related cached responses.Choose your cache strategy
Your caching strategy depends on your attitude toward stale content. Stale content is the one that has expired in the cache. This means the content in Kontent.ai has been updated, but your app continues to serve stale content. If you’re fine with stale content being outdated for 15 minutes or an hour, use time-based caching. This way, you cache each response for the same amount of time. If stale content is an issue and you want to ensure your cache is always up to date, you need to synchronize content changes based on recent content changes in your Kontent.ai project.Fine with stale content? Use time-based caching
For client-side apps and basic mobile apps, we recommend using time-based caching. This means invalidating cached responses after a specific amount of time.- It’s easier to implement.
- It performs better because your app doesn’t need to know about recent content changes and process them.
Need the latest content? Synchronize content changes
Sign in with your Kontent.ai credentials or sign up for free to unlock the full lesson, track your progress, and access exclusive expert insights and tips!