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

Incorporate lru-cache library for basis of async cache logic #34

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,12 @@ aborted, it will stay in the cache.

```js
import AbortablePromiseCache from '@gmod/abortable-promise-cache'
import QuickLRU from 'quick-lru'

const cache = new AbortablePromiseCache({
// QuickLRU is a good backing cache to use, but you can use any
// cache as long as it supports `get`, `set`, `delete`, and `keys`.
cache: new QuickLRU({ maxSize: 1000 }),
max: 1000,

// the `fill` callback will be called for a cache miss
async fill(requestData, abortSignal) {
async fetchMethod(requestData, abortSignal) {
// do some long-running thing
return longRunningThing(requestData, abortSignal)
},
Expand All @@ -40,7 +37,10 @@ const cache = new AbortablePromiseCache({
// Fill requests will be signaled to abort if all the requests for them
// so far have been aborted.
const aborter = new AbortController()
const result = await cache.get('some key', { ...anyStuff }, aborter.signal)
const result = await cache.fetch('some key', {
context: { anyStuff },
signal: aborter.signal,
})

// deleting and clearing will abort any outstanding requests
cache.delete('some key')
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,21 @@
"prepublishOnly": "npm run lint && npm test && npm run build",
"postversion": "git push --follow-tags"
},
"dependencies": {
"lru-cache": "^11.0.0"
},
"devDependencies": {
"@types/node": "^20.14.11",
"@typescript-eslint/eslint-plugin": "^8.0.1",
"@typescript-eslint/parser": "^8.0.1",
"documentation": "^14.0.1",
"eslint": "^9.9.0",
"eslint-plugin-unicorn": "^55.0.0",
"eslint-plugin-unicorn": "^56.0.1",
"prettier": "^3.3.3",
"quick-lru": "^4.0.0",
"rimraf": "^6.0.1",
"typescript": "^5.5.4",
"typescript-eslint": "^8.4.0",
"vitest": "^2.0.5"
"vitest": "^3.0.3"
},
"publishConfig": {
"access": "public"
Expand Down
245 changes: 0 additions & 245 deletions src/AbortablePromiseCache.ts

This file was deleted.

51 changes: 0 additions & 51 deletions src/AggregateAbortController.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/AggregateStatusReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export default class AggregateStatusReporter {

addCallback(callback: Callback = () => {}): void {
this.callbacks.add(callback)
callback(this.currentMessage)
}

callback(message: unknown) {
Expand Down
Loading
Loading