Skip to content
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

Merged
merged 10 commits into from
Nov 21, 2024
Merged

Feat add handler code #3

merged 10 commits into from
Nov 21, 2024

Conversation

tilman
Copy link
Contributor

@tilman tilman commented Nov 19, 2024

No description provided.

// 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);

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);

T extends (...args: [any, any]) => Promise<K>,
K,
> {
private inMemoryDeduplicationCache = new Map<string, Promise<K>>([]);

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.

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

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

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.


if (cacheValue.value?.kind === "FETCH") {
console.time("decoding" + key);
cacheValue.value.data.body = Buffer.from(cacheValue.value.data.body).toString('base64');

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.


const options = getTimeoutRedisCommandOptions(this.timeoutMs);

const deleteKeysOperation = this.client.unlink(

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),

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);

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

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

Copy link

Coverage Report

Coverage after merging feat-add-handler-code into main will be:

Hit/ Total Coverage
🌿 Branches 3 / 7 42.86% 😀
🔢 Functions 1 / 5 20% 😕
📝 Lines 6 / 544 1.1% 🫣

@tilman tilman merged commit 6af8eca into main Nov 21, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants