Buckets:
| import { onCleanup } from "solid-js" | |
| export function createRefCountMap<T>( | |
| create: (key: string) => T, | |
| remove?: (key: string) => void, | |
| identity: (key: string) => string = (key) => key, | |
| ) { | |
| const items = new Map<string, T>() | |
| const refCounts = new Map<string, number>() | |
| return (key: string) => { | |
| const id = identity(key) | |
| onCleanup(() => { | |
| refCounts.set(id, (refCounts.get(id) ?? 0) - 1) | |
| if (refCounts.get(id) === 0) { | |
| remove?.(id) | |
| items.delete(id) | |
| refCounts.delete(id) | |
| } | |
| }) | |
| const cached = items.get(id) | |
| if (cached) { | |
| refCounts.set(id, (refCounts.get(id) ?? 0) + 1) | |
| return cached | |
| } | |
| const item = create(key) | |
| items.set(id, item) | |
| refCounts.set(id, 1) | |
| return item | |
| } | |
| } | |
Xet Storage Details
- Size:
- 772 Bytes
- Xet hash:
- 5a52ffe91c222d77b94bcc107c148a386681aed1a7ae303efc861fb0f81a677b
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.