添加接口

This commit is contained in:
imsyy
2023-03-14 16:04:10 +08:00
parent e9e156b785
commit 583f7f4b4f
23 changed files with 3186 additions and 0 deletions

41
utils/cacheData.js Normal file
View File

@@ -0,0 +1,41 @@
const NodeCache = require("node-cache");
const cache = new NodeCache({
stdTTL: 1800, // 缓存默认过期时间(单位秒)
checkperiod: 60, // 定期检查过期缓存的时间(单位秒)
});
/**
* 从缓存中获取数据
* @param {string} key 缓存键值
* @return {Promise<any>} 数据
*/
const get = async (key) => {
return cache.get(key);
};
/**
* 将数据写入缓存
* @param {string} key 缓存键值
* @param {any} value 数据
* @param {number} ttl 有效期单位秒默认为300秒
* @return {Promise<void>} 无返回值
*/
const set = async (key, value, ttl = 300) => {
return cache.set(key, value, ttl);
};
/**
* 从缓存中删除数据
* @param {string} key 缓存键值
* @return {Promise<void>} 无返回值
*/
const del = async (key) => {
return cache.del(key);
};
module.exports = {
get,
set,
del,
};