-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: improve token list performance by caching target tokens on load…
… and config change
- Loading branch information
1 parent
97643ae
commit 3cc55ff
Showing
11 changed files
with
518 additions
and
35 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
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,35 @@ | ||
import type { Token } from 'rango-sdk'; | ||
|
||
interface CacheServiceInterface<V> { | ||
get<K extends keyof V>(key: K): V[K] | undefined; | ||
set<K extends keyof V>(key: K, value: V[K]): void; | ||
remove<K extends keyof V>(key: K): void; | ||
clear(): void; | ||
} | ||
|
||
class CacheService<T> implements CacheServiceInterface<T> { | ||
#cache: Map<string, T[keyof T]> = new Map(); | ||
|
||
get<K extends keyof T>(key: K): T[K] | undefined { | ||
return this.#cache.get(key as string) as T[K]; | ||
} | ||
|
||
set<K extends keyof T>(key: K, value: T[K]): void { | ||
this.#cache.set(key as string, value); | ||
} | ||
|
||
remove<K extends keyof T>(key: K): void { | ||
this.#cache.delete(key as string); | ||
} | ||
|
||
clear(): void { | ||
this.#cache.clear(); | ||
} | ||
} | ||
|
||
export type CachedEntries = { | ||
supportedSourceTokens: Token[]; | ||
supportedDestinationTokens: Token[]; | ||
}; | ||
|
||
export const cacheService = new CacheService<CachedEntries>(); |
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
Oops, something went wrong.