Skip to content

Commit 0966299

Browse files
committed
rename keyFragments to namespace
1 parent d30e722 commit 0966299

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

src/cache.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,28 @@ const ONE_WEEK = 1000 * 60 * 60 * 24 * 7
2525

2626
interface CachedStorageOptions {
2727
/**
28-
* Array of fragments used to construct the cache key prefix.
29-
* Each fragment can be a string or an object (which will be hashed).
30-
* This allows cache isolation across different contexts (e.g., provider configurations).
28+
* Namespace fragments to isolate cache keys.
3129
*
3230
* @example
3331
* ```ts
3432
* // Isolate cache per provider configuration
3533
* const providerName = 'some-awesome-font-provider'
3634
* const providerOptions = { apiKey: 'xxx', subset: 'latin' }
3735
* createCachedAsyncStorage(storage, {
38-
* keyFragments: [providerName, providerOptions]
36+
* namespace: [providerName, providerOptions]
3937
* })
4038
* ```
4139
*/
42-
keyFragments?: any[]
40+
namespace?: any[]
4341
}
4442

4543
export function createCachedAsyncStorage(storage: Storage, options: CachedStorageOptions = {}) {
4644
function resolveKey(key: string): string {
47-
if (!options?.keyFragments || options.keyFragments.length === 0) {
45+
if (!options?.namespace || options.namespace.length === 0) {
4846
return key
4947
}
5048

51-
return `${createCacheKey(...options.keyFragments)}:${key}`
49+
return `${createCacheKey(...options.namespace)}:${key}`
5250
}
5351

5452
return {

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export async function createUnifont(providers: Provider[], options?: UnifontOpti
4242
function createProviderAwareStorage(providerName: string, providerOptions: unknown): ProviderContext['storage'] {
4343
// https://github.com/unjs/unifont/issues/184
4444
return createCachedAsyncStorage(storageImpl, {
45-
keyFragments: [providerName, providerOptions],
45+
namespace: [providerName, providerOptions],
4646
})
4747
}
4848

test/cache.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe('cache storage', () => {
6565
setItem: vi.fn(),
6666
}
6767
const cached = createCachedAsyncStorage(storage, {
68-
keyFragments: ['provider-name', { a: 1 }, 'variant-a'],
68+
namespace: ['provider-name', { a: 1 }, 'variant-a'],
6969
})
7070
await cached.setItem('test-key', 'data')
7171

@@ -82,10 +82,10 @@ describe('cache storage', () => {
8282
}
8383

8484
const cachedA = createCachedAsyncStorage(storage, {
85-
keyFragments: [{ variant: 'A' }],
85+
namespace: [{ variant: 'A' }],
8686
})
8787
const cachedB = createCachedAsyncStorage(storage, {
88-
keyFragments: [{ variant: 'B' }],
88+
namespace: [{ variant: 'B' }],
8989
})
9090
await cachedA.setItem('key', 'data')
9191
await cachedB.setItem('key', 'data')
@@ -110,7 +110,7 @@ describe('cache storage', () => {
110110
setItem: vi.fn(),
111111
}
112112
const cached = createCachedAsyncStorage(storage, {
113-
keyFragments: [input],
113+
namespace: [input],
114114
})
115115

116116
await cached.setItem('test-key', 'data')

0 commit comments

Comments
 (0)