Simone Sanfratello

Event based cache invalidation in GraphQL

Stop serving stale data. Use event-based invalidation to keep your GraphQL cache instantly up-to-date.

Event based cache invalidation in GraphQL
#1about 2 minutes

Understanding GraphQL resolvers as cacheable functions

GraphQL resolvers can be treated as pure functions, allowing their results to be memoized and cached based on query arguments.

#2about 5 minutes

Comparing time-based and event-based cache invalidation

Time-based invalidation is simple but can serve stale data, whereas event-based invalidation keeps data synced but is more complex to implement.

#3about 4 minutes

Choosing a storage backend and generating cache keys

A cache can use fast in-memory storage for small, frequent data or a shared Redis instance for larger datasets across multiple nodes.

#4about 4 minutes

Using references for targeted cache invalidation

By tagging cache entries with references to the underlying data entities, you can precisely invalidate them when a write event occurs.

#5about 7 minutes

Live demo of setting up a basic GraphQL server

A Fastify server is configured with the Mercurius plugin to serve a GraphQL schema with user and country data from an in-memory database.

#6about 3 minutes

Live demo of implementing a time-based cache policy

The Mercurius Cache plugin is configured with a time-to-live policy for a query, using onHit and onMiss events to verify its effectiveness.

#7about 5 minutes

Live demo of solving stale data with event invalidation

An invalidation function is added to a mutation resolver, which uses references to clear the relevant user data from the cache upon update.

#8about 3 minutes

Exploring advanced features of Mercurius Cache

Mercurius Cache also supports custom key generation, request deduplication, programmatic invalidation with wildcards, and garbage collection for references.

#9about 4 minutes

Q&A on career advice and GraphQL best practices

Common GraphQL pitfalls are discussed, such as neglecting to use DataLoaders to solve the N+1 query problem.

Related jobs
Jobs that call for the skills explored in this talk.

job ad

Saby Company
Delebio, Italy

Intermediate

d

Saby Company
Delebio, Italy

Junior

Featured Partners

Related Articles

View all articles
CH
Chris Heilmann
Dev Digest 139 - Soft and hard queries
News and ArticlesLet's start with Amelia Wattenberger's excellent essay Bridging the hard and the soft talking about humans and data. Do you sometimes also miss aspects of the early web like a lack of big data and freedom to create without numeric go...
Dev Digest 139 - Soft and hard queries
CH
Chris Heilmann
Dev Digest 109 -Egg-citing things…
As we are heading into the Easter break, here are some things to spend some time on. There's resources on improving the performance of your code and you hear from the winners of CODE100 Amsterdam what it was like to be on stage. Also, hang tight as t...
Dev Digest 109 -Egg-citing things…
CH
Chris Heilmann
All the videos of Halfstack London 2024!
Last month was Halfstack London, a conference about the web, JavaScript and half a dozen other things. We were there to deliver a talk, but also to record all the sessions and we're happy to share them with you. It took a bit as we had to wait for th...
All the videos of Halfstack London 2024!
EM
Eli McGarvie
Stop Wasting Time: How to Lead a Stand-Up Meeting & Get Results
We all know the feeling: your stand-up meeting starts… and the energy in the room slowly deflates. Eyes glaze over, minds wander. Maybe you can even see their attention drop on smartphones or laptops.Within minutes or even seconds, instead of a quick...
Stop Wasting Time: How to Lead a Stand-Up Meeting & Get Results

From learning to earning

Jobs that call for the skills explored in this talk.