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

Add isExpired helper #122

Merged
merged 1 commit into from
Feb 7, 2025
Merged

Add isExpired helper #122

merged 1 commit into from
Feb 7, 2025

Conversation

Xiphe
Copy link
Collaborator

@Xiphe Xiphe commented Feb 7, 2025

I found myself sometimes needing to manually check the validity/expired-state of a cache entry.

The exported shouldRefresh helper is capable of doing that but the naming is unintuitive when used outside of cachified itself.

import {
  createCacheEntry,
  isExpired,
  shouldRefresh
} from '@epic-web/cachified';

const myEntry = createCacheEntry('hello', { ttl: 50 });

// intuitive
isExpired(myEntry.metadata);

// has internal flavour
shouldRefresh(myEntry.metadata);

This also deprecates the shouldRefresh helper in favor of the new API

I found myself sometimes needing to manually check the validity/expired-stat of a cache entry
the exported `shouldRefresh` helper is capable of doing that but
the naming is unintuitive when used outside of cachified itself

when I look at a cache entry manually, i want to know "is is expired/valid" not "should i refresh"
@Xiphe Xiphe requested a review from kentcdodds February 7, 2025 12:44
Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

Thanks a lot, I'll probably use this too!

@kentcdodds kentcdodds merged commit 2070f4e into main Feb 7, 2025
4 checks passed
@kentcdodds kentcdodds deleted the is-expired-helper branch February 7, 2025 19:07
Copy link

github-actions bot commented Feb 7, 2025

🎉 This PR is included in version 5.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

2 participants