MCPcopy Create free account
hub / github.com/RealDevSquad/website-backend / cachedKeysStore

Function cachedKeysStore

utils/cache.js:78–130  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

76 const clear = () => {
77 cacheStore.clear();
78 };
79
80 return { get, set, evict, clear, hits, cacheStore };
81};
82/**
83 * A MultiMap implementation where each key maps to set of unique values.
84 * It internally uses Map to store keys and values and to save multiple values it uses Set. Map<string,Set<string>>
85 */
86const cachedKeysStore = () => {
87 const keyStore = new Map();
88
89 /**
90 * Returns set of values mapped to given key
91 * @param {string} modelKey key for the map
92 * @returns {Set} set of values
93 */
94 const getCachedKeys = (modelKey) => {
95 if (!keyStore.has(modelKey)) {
96 return new Set();
97 }
98 return keyStore.get(modelKey);
99 };
100
101 /**
102 * Adds a value(cachedKey) for the given key(modelKey)
103 * @param {string} modelKey key for the map
104 * @param {string} cachedKey value for the given key
105 *
106 */
107 const addCachedKey = (modelKey, cachedKey) => {
108 if (keyStore.has(modelKey)) {
109 keyStore.get(modelKey).add(cachedKey);
110 } else {
111 const set = new Set();
112 set.add(cachedKey);
113 keyStore.set(modelKey, set);
114 }
115 };
116 /**
117 * removes the given key(modelKey) and all of its associated values
118 * @param {string} modelKey key for the map
119 *
120 */
121 const removeModelKey = (modelKey) => {
122 keyStore.delete(modelKey);
123 };
124
125 /**
126 * remove a value(cachedKey) for the given key(modelKey)
127 * @param {string} modelKey key for the map
128 * @param {string} cachedKey value for the given key
129 *
130 */
131 const removeCachedKey = (modelKey, cachedKey) => {
132 if (keyStore.has(modelKey)) {
133 keyStore.get(modelKey).delete(cachedKey);

Callers 2

cache.jsFile · 0.85
cache.test.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected