Ver Fonte

feat: Added DEL function to cache module

Owen Diffey há 2 anos atrás
pai
commit
59815962cc
1 ficheiros alterados com 28 adições e 0 exclusões
  1. 28 0
      backend/logic/cache/index.js

+ 28 - 0
backend/logic/cache/index.js

@@ -225,6 +225,34 @@ class _CacheModule extends CoreClass {
 		});
 	}
 
+	/**
+	 * Deletes a single value
+	 *
+	 * @param {object} payload - object containing payload
+	 * @param {string} payload.key - name of the key to delete
+	 * @returns {Promise} - returns a promise (resolve, reject)
+	 */
+	DEL(payload) {
+		return new Promise((resolve, reject) => {
+			let { key } = payload;
+
+			if (!key) {
+				reject(new Error("Invalid key!"));
+				return;
+			}
+
+			if (mongoose.Types.ObjectId.isValid(key)) key = key.toString();
+
+			CacheModule.client.del(key, err => {
+				if (err) {
+					reject(new Error(err));
+					return;
+				}
+				resolve();
+			});
+		});
+	}
+
 	/**
 	 * Publish a message to a channel, caches the redis client connection
 	 *