-
Notifications
You must be signed in to change notification settings - Fork 9
ts-sdk: Add time-based lru caching for the decryptChannelDEK #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…gination in the integration-write test
…achments. chore(ts-sdk): cleanup the integration tests.
| this.#sessionKey = config.sessionKey; | ||
| this.#sessionKeyConfig = config.sessionKeyConfig; | ||
| this.#encryptionPrimitives = config.encryptionPrimitives ?? WebCryptoPrimitives.getInstance(); | ||
| this.#dekCache = new TimeBasedLruCache({ ttlMs: 5 * 60 * 1000, maxEntries: 100 }); // 5 minutes TTL, 100 max entries |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be configurable. let's open a ticket for that.
| ]; | ||
|
|
||
| // Use cache with loader function | ||
| return await this.#dekCache.read(cacheKey, async (): Promise<SymmetricKey> => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that, await is not needed here
| import { EncryptedObject, SessionKey } from '@mysten/seal'; | ||
| import { fromHex, isValidSuiObjectId, toHex } from '@mysten/sui/utils'; | ||
|
|
||
| import { TimeBasedLruCache } from '../cache.js'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need the suffix?
| } | ||
|
|
||
| export class TimeBasedLruCache { | ||
| #cache: Map<string, { value: unknown; timestampMs: number }>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These 3 -> readonly
| } | ||
| this.#set(cacheKey, result); | ||
|
|
||
| return result as T; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as T is not needed I believe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you gonna use these consts?
decryptChannelDEKmethod, in order to significantly reduce redundant rpc requests.