Skip to content

Commit c7f1bab

Browse files
committed
feat: add swr alias for staleWhileRevalidate option
1 parent 6c05538 commit c7f1bab

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ interface CachifiedOptions<Value> {
122122
* Default: `0`
123123
*/
124124
staleWhileRevalidate?: number;
125+
/**
126+
* Alias for staleWhileRevalidate
127+
*/
128+
swr?: number;
125129
/**
126130
* Validator that checks every cached and fresh value to ensure type safety
127131
*

src/cachified.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ describe('cachified', () => {
10511051
cache,
10521052
key: 'test',
10531053
ttl: 5,
1054-
staleWhileRevalidate: 5,
1054+
swr: 5,
10551055
getFreshValue,
10561056
});
10571057

src/common.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ export interface CachifiedOptions<Value> {
115115
* Default: `0`
116116
*/
117117
staleWhileRevalidate?: number;
118+
/**
119+
* Alias for staleWhileRevalidate
120+
*/
121+
swr?: number;
118122
/**
119123
* Validator that checks every cached and fresh value to ensure type safety
120124
*
@@ -192,7 +196,7 @@ export type CachifiedOptionsWithSchema<Value, InternalValue> = Omit<
192196
export interface Context<Value>
193197
extends Omit<
194198
Required<CachifiedOptions<Value>>,
195-
'fallbackToCache' | 'reporter' | 'checkValue'
199+
'fallbackToCache' | 'reporter' | 'checkValue' | 'swr'
196200
> {
197201
checkValue: CheckValue<Value>;
198202
report: Reporter<Value>;
@@ -207,7 +211,7 @@ export function createContext<Value>({
207211
...options
208212
}: CachifiedOptions<Value>): Context<Value> {
209213
const ttl = options.ttl ?? Infinity;
210-
const staleWhileRevalidate = options.staleWhileRevalidate ?? 0;
214+
const staleWhileRevalidate = options.swr ?? options.staleWhileRevalidate ?? 0;
211215
const checkValueCompat: CheckValue<Value> =
212216
typeof checkValue === 'function'
213217
? checkValue

0 commit comments

Comments
 (0)