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: add expire method #56

Merged
merged 1 commit into from
Feb 11, 2025
Merged

feat: add expire method #56

merged 1 commit into from
Feb 11, 2025

Conversation

Julien-R44
Copy link
Owner

add a new expire method

this method is slightly different from delete:

  • when we delete a key, it is completely removed and forgotten. This means that even if we use grace periods, the value will no longer be available.
  • expire works like delete, except that instead of completely removing the value, we just mark it as expired but keep it for the grace period. For example:
// Set a value with a grace period of 6 minutes
await cache.set({ 
  key: 'hello',
  value: 'world',
  grace: '6m'
})

// Expire the value. It is kept in the cache but marked as STALE for 6 minutes
await cache.expire({ key: 'hello' })

// Here, a get with grace: false will return nothing, because the value is stale
const r1 = await cache.get({ key: 'hello', grace: false })

// Here, a get with grace: true will return the value, because it is still within the grace period
const r2 = await cache.get({ key: 'hello' })

assert.deepEqual(r1, undefined)
assert.deepEqual(r2, 'world')

Copy link

changeset-bot bot commented Feb 11, 2025

🦋 Changeset detected

Latest commit: 5e88efe

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

This PR includes changesets to release 1 package
Name Type
bentocache Minor

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

@Julien-R44 Julien-R44 merged commit 8bb87b6 into main Feb 11, 2025
9 checks passed
@Julien-R44 Julien-R44 deleted the feat/expire-method branch February 11, 2025 22:43
@dunhamjared
Copy link

Ooooo this is awesome!

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