refactor(web): extract notification object cache prefix to a constant

This commit is contained in:
Pujit Mehrotra
2024-10-29 11:31:29 -04:00
parent d9d5a24b70
commit 1da882b807
2 changed files with 7 additions and 3 deletions

View File

@@ -1,5 +1,6 @@
import { InMemoryCache, type InMemoryCacheConfig } from "@apollo/client/core";
import { mergeAndDedup } from "./merge";
import { NOTIFICATION_CACHE_PREFIX } from "./prefixes";
/**------------------------------------------------------------------------
* ! Understanding Cache Type Policies
@@ -89,9 +90,7 @@ const defaultCacheConfig: InMemoryCacheConfig = {
*/
merge(_, incoming, { cache, args }) {
if (args?.id) {
// The magic 'Notification:' prefix comes from inspecting the apollo cache
// I think it comes from the __typename when apollo caches an object (by default)
cache.evict({ id: `Notification:${args.id}` });
cache.evict({ id: `${NOTIFICATION_CACHE_PREFIX}:${args.id}` });
}
// Removes references to evicted notification, preventing dangling references
cache.gc();

View File

@@ -0,0 +1,5 @@
/**
* The magic 'Notification' prefix comes from inspecting the apollo cachel.
* I think it comes from the __typename when apollo caches an object (by default)
*/
export const NOTIFICATION_CACHE_PREFIX = "Notification";