-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feat add handler code #3
Conversation
// Method to manually seed a result into the cache | ||
seedRequestReturn(key: string, value: K): void { | ||
const resultPromise = new Promise<K>((res) => res(value)); | ||
this.inMemoryDeduplicationCache.set(key, resultPromise); |
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.
Right now we have two problems:
- everything seeded by seedRequestReturn will not get deleted after cachingTimeMs. Add the same timeout as in deduplicated function:
setTimeout(() => {
self.inMemoryDeduplicationCache.delete(key);
}, self.cachingTimeMs);
src/DeduplicatedRequestHandler.ts
Outdated
T extends (...args: [any, any]) => Promise<K>, | ||
K, | ||
> { | ||
private inMemoryDeduplicationCache = new Map<string, Promise<K>>([]); |
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.
Cache entries which are set in in-memory request will not get deleted by revalidateTag across all nodes (only on local instance). Add keyspace notification to make sure this will get deleted as well.
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 problem does not exist if inMemoryCaching is set to 0
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.
If inMemoryCaching is enabled. It will degrade caching consistency from strong to eventual consistency. Add this to the README
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.
Check if redis will always serve a get after a set.
src/RedisStringsHandler.ts
Outdated
|
||
if (cacheValue.value?.kind === "FETCH") { | ||
console.time("decoding" + key); | ||
cacheValue.value.data.body = Buffer.from(cacheValue.value.data.body).toString('base64'); |
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.
Check if redis can handle every character encoding. It should return the same as we passed in.
src/RedisStringsHandler.ts
Outdated
|
||
const options = getTimeoutRedisCommandOptions(this.timeoutMs); | ||
|
||
const deleteKeysOperation = this.client.unlink( |
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.
Check if we have a different consistency if used with del
await this.subscriberClient.connect(); | ||
|
||
await Promise.all([ | ||
this.subscriberClient.subscribe(this.syncChannel, syncHandler), |
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.
Add message why custom pub/sub channel for delete and insert:
With custom channel we can delete multiple entries in one message. If we would listen to unlink/del we could get thousends of messages for one revalidateTag (For example revalidateTag("algolia") would send an enourmous amount of packages)
src/SyncedMap.ts
Outdated
if (key.startsWith(this.keyPrefix)) { | ||
const keyInMap = key.substring(this.keyPrefix.length); | ||
if (this.filterKeys(keyInMap)) { | ||
await this.delete(keyInMap); |
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.delete will unnecesarly send a pub sub message out which will call this.map.delete again.
Overhead: multiple pub sub messages + multiple this.map.delete calls
Solution: add opton to this.delete to not send out pub sub message. Therefore check if keyevent is received by all connected clients or only by one of the connected clients
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.
Callflow:
expired event ->
keyEventHandler ->
this.delete ->
this.map.delete
this.client.hDel
this.client.publish ->
syncHandler ->
this.map.delete
Currently race condition is possible if this.map.set is called before second this.map.delete.
Goal: remove second this.map.delete
Coverage ReportCoverage after merging
|
No description provided.