DocumentationLogin
Enterspeed logo
Enterspeed Blog
Product

Automatic Cache invalidation with Enterspeed

Kasper Andreassen
Kasper Andreassen
UX Engineer at Enterspeed
Thumbnail for blog post: Automatic Cache invalidation with Enterspeed

Enterspeed is a high-performing API often used for Jamstack-based websites. We frequently describe us as a combination of an integration layer and an API hosting platform, but in many ways, Enterspeed can be considered a cache.

However, two key features differentiates Enterspeed from traditional caches:

1) Pre-processing

2) Automatic cache invalidation

These two strategies ensure that all data in Enterspeed's Delivery API is always ready to be served from the cache. In this blog post, we’ll delve into the technical details of automatic cache invalidation.

Caching and Automatic Invalidation

Caching and Automatic Invalidation

Caching is a popular technique used in software development to improve performance by storing frequently accessed data in a temporary storage location, known as a cache, for quick retrieval rather than fetching it from the original data source every time. However, one challenge with caching is keeping the cached data up to date when the underlying data changes. This is where automatic cache invalidation comes into play. In this blog post, we will explain how we work with automatic cache invalidation in Enterspeed and how it can enhance performance and consistency for your websites.

What is Automatic Cache Invalidation?

Automatic cache invalidation is a mechanism that automatically removes or updates cached data when the underlying data changes. When data in the original data source is updated, added, or deleted, the cache is automatically invalidated, ensuring that the next request fetches the latest data from the original data source rather than stale data from the cache. This ensures that the data stored in the cache remains consistent with the actual data source.

It is important to note that in Enterspeed, we go beyond merely invalidating the cache; we pre-process the new and updated data and insert it into the cache.

Why Does Automatic Cache Invalidation Matter?

I mean, does it really matter GIF

Automatic cache invalidation is essential for maintaining data consistency and ensuring that your application serves up-to-date data to users. Without cache invalidation, the cached data may become stale and outdated, leading to incorrect results or inconsistent behaviour. For example, imagine an e-commerce application that caches product prices. If a product price changes in the database but the cache is not invalidated, users may see outdated prices, resulting in incorrect calculations or even financial losses. Automatic cache invalidation helps prevent such inconsistencies and ensures that your application always serves the latest and accurate data.

Boosting Performance with Automatic Cache Invalidation

Porsche 911 rally car

To make Automatic Cache Invalidation work, we have defined a set of clear cache invalidation rules. And we have a 100% cache hit rate, as we never use time as a cache invalidation strategy. Instead, we rely on event-driven mechanisms and, together with a variant of donut-caching and simple re-processing hints, you will always fetch data from the cache.

Event-driven Invalidation

Through the Enterspeed Ingest API, our customers send a copy of every piece of data from their CMS or other source systems. For Enterspeed, this means that we simply react when the source system sends us new, updated, or removed data.

To minimise over-processing, Enterspeed automatically stops processing unchanged data.

Donut-caching

Homer Simpson eating donuts GIF

Donut-caching refers to the concept of punching holes in the cached data so that dynamic elements are inserted into the holes in the final response from the server. Enterspeed works similarly, stitching together a Delivery API response from multiple separate cached items. Each item is updated only when the exact piece of source data that makes up the data item is updated. When one item is requested, that item only holds a reference to the other pieces of data used to form the response.

One example is a list of news articles. On the list of news articles, only the title and date of the article are used, but instead of storing the title and date on the data item that has the list of news articles, only a reference is stored. When one of the news article's titles is updated, it’s not necessary to rebuild the list but only update the individual article. When the list of news articles is requested, the response is made up of a combination of the multiple individual items.

The donut-caching strategy works very well to update individual items, but when the context changes, another strategy is needed.

Re-processing Hints

In situations when the list itself changes – i.e., the order changes or a news article is deleted – the list also needs to be regenerated. The target for automatic cache invalidation is always to invalidate the smallest possible amount of cache entries. In Enterspeed, we achieve this with what we call actions, but you can think of them as re-processing hints.

We have delegated this responsibility to the developers using Enterspeed, so they can define which parts of the cache need to be automatically invalidated when individual items change.

The point being...

Enterspeed's innovative approach to automatic cache invalidation is instrumental in maintaining data consistency and optimising performance for applications.

By incorporating an effective cache invalidation strategy alongside features such as pre-processing, event-driven invalidation, donut-caching, and re-processing hints, Enterspeed ensures that your cache is consistently updated with the latest data.

This not only prevents potential discrepancies but also delivers the most accurate and reliable information to your users, making Enterspeed an excellent solution for your web development needs.

Try automatic caching with Enterspeed yourself 🚀

Kasper Andreassen
Kasper Andreassen
UX Engineer at Enterspeed

Loves optimizing and UX. Proud father of two boys and a girl. Scared of exercise and fond of beer.

Ready to try out Enterspeed? 🚀

Start combining & connecting your services today

Product

Why Enterspeeed?Use casesBuild vs. buyIntegrations

Company

Partners ☕ Let's talk!About UsContact UsTerms of ServicePrivacy PolicySecurity
Enterspeed logo

© 2020 - 2024 Enterspeed A/S. All rights reserved.

Made with ❤️ and ☕ in Denmark.