Custom Cache plugin in Fastify using hooks and node-cache.
➥ Repo: https://github.com/pragmatic-reviews/...
➥ Buy Me a Coffee: https://buymeacoff.ee/pragmatic
➥ node-cache module: https://github.com/node-cache/node-cache
➥ Fastify Lifecycle: https://www.fastify.io/docs/latest/Li...
➥➥ Learn even more! ➥➥
Learn Next.js ➥ https://bit.ly/PragmaticNext
Learn Contentful ➥ https://bit.ly/PragmaticContentful
Learn Strapi ➥ http://bit.ly/PragmaticStrapi
Learn Gatsby ➥ https://bit.ly/PragmaticGatsby
Learn Deno ➥ https://bit.ly/LearnDeno
Learn GraphQL ➥ https://bit.ly/LearnGraphQL
Golang in the Cloud ➥ https://bit.ly/LearnGolangCloud
Gin Crash Course ➥ http://bit.ly/2SXdJu2
Golang Crash Course ➥ http://bit.ly/39ZH8dy
Zapier Crash Course ➥ http://bit.ly/37q1BGt
Timestamps:
Intro - 0:00
What we’ve done so far - 0:40
Setting up the cache plugin and node-cache module - 1:16
Setting up the custom cache with hooks (onRequest) - 2:37
Setting up the custom cache with hooks (onSend) - 5:12
Setting up a TTL for the keys of the cache - 7:05
Using Fastify Plugin to enable access from parent context - 7:45
Adding function to handle node-cache’s ‘expired’ event - 8:39
Adding console logging - 9:33
Fixing parameters of ‘expired’ event handler (key, value) - 11:20
Testing custom cache - 11:36
Outro - 12:43
#Fastify #Hooks #Cache