mirror of
https://github.com/unraid/api.git
synced 2026-01-02 06:30:02 -06:00
refactor(web): extract notification object cache prefix to a constant
This commit is contained in:
@@ -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();
|
||||
|
||||
5
web/helpers/apollo-cache/prefixes.ts
Normal file
5
web/helpers/apollo-cache/prefixes.ts
Normal 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";
|
||||
Reference in New Issue
Block a user