-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add simple server side cache and list sets in the sidebar nav
- Loading branch information
Showing
9 changed files
with
135 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import QuickLRU from 'quick-lru'; | ||
|
||
// Default cache configuration | ||
const DEFAULT_MAX_SIZE = 100; | ||
const DEFAULT_MAX_AGE = 600000; // 10 minutes in milliseconds | ||
|
||
// Single global cache instance | ||
const globalCache = new QuickLRU<string, unknown>({ | ||
maxSize: DEFAULT_MAX_SIZE, | ||
maxAge: DEFAULT_MAX_AGE, | ||
}); | ||
|
||
/** | ||
* Invalidate entire cache namespace | ||
* @param name Cache namespace to invalidate | ||
*/ | ||
export function invalidateCache(name: string): void { | ||
globalCache.delete(name); | ||
} | ||
|
||
/** | ||
* Cached loader utility | ||
* @param name Cache name | ||
* @param fetchFn Function to fetch data if not in cache | ||
*/ | ||
export async function cachedLoader<V>( | ||
name: string, | ||
fetchFn: () => Promise<V>, | ||
): Promise<V> { | ||
// Check cache first | ||
const cachedData = globalCache.get(name); | ||
if (cachedData !== undefined) { | ||
return cachedData as V; | ||
} | ||
|
||
// Fetch and cache new data | ||
const freshData = await fetchFn(); | ||
globalCache.set(name, freshData); | ||
|
||
return freshData; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters