New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

siyuan_api_cache_lib

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

siyuan_api_cache_lib - npm Package Compare versions

Comparing version

to
1.0.5

17

dist/cache/api-cache.js

@@ -9,3 +9,3 @@ import { config } from "../config";

*/
function cache(f) {
function cache(f, funcName = f.name) {
return (async (...arg) => {

@@ -18,3 +18,3 @@ if (config.apiCache &&

if (id) {
const key = getCacheKey(f, arg);
const key = getCacheKey(funcName, arg);
const value = JSON.stringify(r);

@@ -37,3 +37,3 @@ if (value.length <= config.maxCacheValueLength) {

if (getCurrentEnv() !== getCurrentEnv.env.siYuan) {
return cacheExtract(f, arg);
return cacheExtract(funcName, arg);
}

@@ -53,3 +53,3 @@ else {

//@ts-ignore 这里类型比较复杂,不想写
warp[key] = cache(element);
warp[key] = cache(element, key);
}

@@ -64,4 +64,4 @@ else {

/** 从缓存提取以前对此参数调用的结果 */
function cacheExtract(f, arg) {
const key = getCacheKey(f, arg);
function cacheExtract(funcName, arg) {
const key = getCacheKey(funcName, arg);
const env = getCurrentEnv();

@@ -82,5 +82,6 @@ if (env === getCurrentEnv.env.siYuan) {

}
function getCacheKey(f, arg) {
function getCacheKey(funcName, arg) {
// 存在 缺陷,当函数名称变化时,缓存的 key 也会变化
/** 这里本来是 custom-call 改成 z 是为了在思源内的属性面板中排最后 对于用户来说应该不会很关心这里的数据 */
return `custom-z-${f.name.toLowerCase()}-${cyrb53(`${f.name}__${JSON.stringify(arg)}`)}`;
return `custom-z-${funcName.toLowerCase()}-${cyrb53(`${funcName}__${JSON.stringify(arg)}`)}`;
}

@@ -87,0 +88,0 @@ //@ts-ignore 代码来自于 https://stackoverflow.com/a/52171480

{
"name": "siyuan_api_cache_lib",
"version": "1.0.4",
"version": "1.0.5",
"description": "为思源挂件块提供 api 访问的工具库,同时具有缓存 api 调用结果到块属性上以及在非思源笔记环境下使用缓存结果的功能",

@@ -5,0 +5,0 @@ "main": "dist/index.js",