Skip to content

Commit

Permalink
Add caching ADR
Browse files Browse the repository at this point in the history
  • Loading branch information
lsolcher committed Dec 5, 2024
1 parent 928c397 commit 2d1d5e9
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions doc/adr/0008-use-serverside-caching.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# 8. Use Server-Side Caching with NodeCache for Strapi Data Fetching

**Date:** 2024-12-05

## Status

Accepted

## Context

This comment has been minimized.

Copy link
@HendrikSchmidt

HendrikSchmidt Dec 5, 2024

Contributor

You could maybe add some context on our "over-complicated" data structure leading to high loading times with GraphQL and that our content changes very seldomly, making caching a very good option?


Fetching data from Strapi frequently can result in performance
bottlenecks and increased latency, especially when querying the same
data repeatedly in a short time span. This can impact user experience.

This comment has been minimized.

Copy link
@monachilada

monachilada Dec 5, 2024

Contributor

Can also impact infrastructure load / efficiency / costs.


Previously, our approach did not involve caching, leading to:

- **Repeated requests** for identical GraphQL queries, increasing load on the Strapi server.
- **Higher response times** for end-users, particularly for frequently accessed resources.

To address these issues, we evaluated multiple solutions for
implementing caching to reduce redundant calls and improve performance.

### Evaluated Options

1. **Caching in Strapi with Apollo:**

- Apollo's built-in caching features were explored for use within Strapi.
- However, integration issues made it impractical for our needs, and it failed to provide the expected benefits.

2. **External Caching Services (e.g., Redis):**

- High scalability and flexibility.
- Requires additional infrastructure setup and maintenance.
- Overhead may not be justified for our current scale.

3. **In-Memory Caching with NodeCache:**
- Simple to integrate directly into the application code.
- Minimal setup with built-in TTL (time-to-live) and periodic cleanup.
- Well-suited for small-scale, server-side caching needs.

## Decision

We decided to use **NodeCache** for implementing server-side caching in our data-fetching layer.
This approach is lightweight and integrates seamlessly with our existing architecture.

Key considerations for choosing NodeCache:

- **Simplicity:** Straightforward Integration.
- **Low Overhead:** As an in-memory solution, it requires no additional external service or infrastructure.
- **Global Caching:** We opted to cache entire responses for specific queries globally instead of caching individual fields. This is because we do not have a large variety of different requests, making global caching simpler and more effective.

This comment has been minimized.

Copy link
@HendrikSchmidt

HendrikSchmidt Dec 5, 2024

Contributor

And no user specific data!

- **TTL Management:** Built-in support for automatic expiration of cached data aligns with our need for caching dynamic content with a short lifespan.

This comment has been minimized.

Copy link
@HendrikSchmidt

HendrikSchmidt Dec 5, 2024

Contributor

aren't we caching static data with long lifespans? :D

- **Immediate Benefits:** It reduces repeated requests for identical GraphQL queries to Strapi, improving performance and decreasing server load.

## Consequences

We will use `node-cache` to cache requests to Strapi.

This comment has been minimized.

Copy link
@HendrikSchmidt

HendrikSchmidt Dec 5, 2024

Contributor

Could you go into a bit more detail here on how the caching works (centrally, cached by query) and possible side effects (users getting outdated info for a while as long as the cache is fresh)?

2 comments on commit 2d1d5e9

@monachilada
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice findings and write-up! 🙏

@HendrikSchmidt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the documentation! 📑

Please sign in to comment.