Skip to content

Commit

Permalink
feat: Add trigger for cache.evict and cache.modify, return results of…
Browse files Browse the repository at this point in the history
… functions
  • Loading branch information
Fándly Gergő authored and wtrocki committed Sep 29, 2020
1 parent 9ef0869 commit 4881e28
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/onCacheWrite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,28 @@ export default <T>({ cache }: TriggerFunctionConfig<T>) => (
persist: () => void,
) => {
const write = cache.write;
const evict = cache.evict;
const modify = cache.modify;

cache.write = (...args: any[]) => {
const ref = write.apply(cache, args);
const result = write.apply(cache, args);
persist();
return result;
};
cache.evict = (...args: any[]) => {
const result = evict.apply(cache, args);
persist();
return result;
};
cache.modify = (...args: any[]) => {
const result = modify.apply(cache, args);
persist();
return ref;
return result;
};

return () => {
cache.write = write;
cache.evict = evict;
cache.modify = modify;
};
};

0 comments on commit 4881e28

Please sign in to comment.