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

feat: customizable cache key #52

Merged
merged 4 commits into from
Sep 15, 2023
Merged

feat: customizable cache key #52

merged 4 commits into from
Sep 15, 2023

Conversation

johannschopplich
Copy link
Owner

πŸ”— Linked issue

#50

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme or JSDoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Supersedes #51.

@killjoy1221 Adds support for a custom key to de-duplicate requests, just like asyncData does:

cost route = useRoute()

const { data, pending, error } = await useJsonPlaceholderData<JsonPlaceholderComment>(
  // Key can be reactive
  computed(() => route.params.slug)
  'comments',
  {
    query: computed(() => ({
      postId: `${route.query.postId || 1}`,
    })),
)

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@netlify
Copy link

netlify bot commented Sep 15, 2023

βœ… Deploy Preview for nuxt-api-party ready!

Name Link
πŸ”¨ Latest commit 37141f0
πŸ” Latest deploy log https://app.netlify.com/sites/nuxt-api-party/deploys/6504b701b14e6d0008fe712b
😎 Deploy Preview https://deploy-preview-52--nuxt-api-party.netlify.app
πŸ“± Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mattmess1221
Copy link
Contributor

The useApiData looks good, but I don't think $api needs a dedicated parameter. Adding an optional first argument will just complicate the logic and types.

Since caching is disabled by default, could the cache option be used for that? If set to true, generate a default key. Otherwise it's a string, ref, or getter function usage in toValue()

@johannschopplich
Copy link
Owner Author

I like it!

@mattmess1221
Copy link
Contributor

mattmess1221 commented Sep 15, 2023

LGTM

@johannschopplich johannschopplich changed the title feat: customizable async data key feat: customizable cache key Sep 15, 2023
@johannschopplich johannschopplich merged commit a1ee25e into main Sep 15, 2023
@johannschopplich johannschopplich deleted the feat/custom-key branch September 15, 2023 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants