Skip to content

Commit

Permalink
Use a shorter cache lookup strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
Lotes committed Jun 20, 2024
1 parent 64c6f62 commit ce1d9d6
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions hugo/content/docs/recipes/utilities/caches.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,9 @@ export class CachedInferPublisherService extends UncachedInferPublisherService {
}
override inferPublisher(person: Person): KnownPublisher|undefined {
const documentUri = AstUtils.getDocument(person).uri;
if(this.cache.has(documentUri, person)) {
return this.cache.get(documentUri, person)!;
}
const publisher = super.inferPublisher(person);
this.cache.set(documentUri, person, publisher);
return publisher;
//get cache entry for the documentUri and the person
//if it does not exist, calculate the value and store it
return this.cache.get(documentUri, person, () => super.inferPublisher(person));
}
}
```
Expand Down Expand Up @@ -210,12 +207,7 @@ export class CachedInferPublisherService extends UncachedInferPublisherService {
}
override inferPublisher(person: Person): KnownPublisher|undefined {
const documentUri = AstUtils.getDocument(person).uri;
if(this.cache.has(documentUri, person)) {
return this.cache.get(documentUri, person)!;
}
const publisher = super.inferPublisher(person);
this.cache.set(documentUri, person, publisher);
return publisher;
return this.cache.get(documentUri, person, () => super.inferPublisher(person));
}
}
```
Expand Down

0 comments on commit ce1d9d6

Please sign in to comment.