Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEV-2122] implement in-memory caching for CMS API data retrieval #1318

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tommaso1
Copy link
Collaborator

List of Changes

  • Introduced a new cache.ts file to manage an in-memory cache for API responses.
  • Updated multiple functions in cmsApi.ts to utilize the caching mechanism, improving performance by reducing redundant API calls.
  • Each API function now caches results for 15 minutes (900 seconds) using a unique cache key generated by getCacheKey.
  • Enhanced type safety by replacing any with unknown in the cache implementation.

This change optimizes data fetching and reduces load on the CMS API.

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Chore (nothing changes by a user perspective)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

- Introduced a new `cache.ts` file to manage an in-memory cache for API responses.
- Updated multiple functions in `cmsApi.ts` to utilize the caching mechanism, improving performance by reducing redundant API calls.
- Each API function now caches results for 15 minutes (900 seconds) using a unique cache key generated by `getCacheKey`.
- Enhanced type safety by replacing `any` with `unknown` in the cache implementation.

This change optimizes data fetching and reduces load on the CMS API.
Copy link

changeset-bot bot commented Jan 21, 2025

🦋 Changeset detected

Latest commit: c2d44b4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
nextjs-website Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

Bundle not found for branch main.
It wasn't possible to compare bundles size.

Copy link
Contributor

Branch is not up to date with base branch

@tommaso1 it seems this Pull Request is not updated with base branch.
Please proceed with a merge or rebase to solve this.

Copy link
Contributor

github-actions bot commented Jan 28, 2025

Jira Pull Request Link

This Pull Request refers to the following Jira issue DEV-2122

const strapiHomepage = await fetchHomepage(buildEnv);
return makeHomepageProps(strapiHomepage);
},
900 // 15 minutes in seconds
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe we should convert this into a env var ot at least a constant in this file

Suggested change
900 // 15 minutes in seconds
900 // 15 minutes in seconds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants