摘要:地址用于通過緩存具有相同輸入的調(diào)用結(jié)果來加速連續(xù)函數(shù)調(diào)用的優(yōu)化普通用法支持基于的異步函數(shù)調(diào)用第二參數(shù)用法用法設(shè)置緩存時(shí)長(zhǎng),默認(rèn)默認(rèn)所有參數(shù)相同才啟用緩存數(shù)據(jù),但你也可以設(shè)置只緩存第一個(gè)參數(shù)也就是只要第一個(gè)參數(shù)相同,就采用緩存值設(shè)置緩存方式,
[github地址:https://github.com/ABCDdouyae...]
mem用于通過緩存具有相同輸入的調(diào)用結(jié)果來加速連續(xù)函數(shù)調(diào)用的優(yōu)化
const mem = require("mem"); let i = 0; let a = () => i++; let mem_a = mem(a); mem_a(); console.log(i);//1 mem_a(); console.log(i);//1 mem_a(10); console.log(i);//2 mem_a(); console.log(i);//2 mem_a(11); console.log(i);//3
let b = async () => j++; let mem_b = mem(b); (async ()=> { await mem_b(); console.log(j);//1 await mem_b(); console.log(j);//1 await mem_b(10); console.log(j);//2 })();
用法:mem(Function, options|object)
maxAge:設(shè)置緩存時(shí)長(zhǎng),默認(rèn)infinity
const mem = require("mem"); const got = require("got"); const delay = require("delay"); const memGot = mem(got, {maxAge: 1000}); (async () => { await memGot("sindresorhus.com"); // This call is cached await memGot("sindresorhus.com"); await delay(2000); // This call is not cached as the cache has expired await memGot("sindresorhus.com"); })();
cacheKey:默認(rèn)所有參數(shù)相同才啟用緩存數(shù)據(jù),但你也可以設(shè)置只緩存第一個(gè)參數(shù)(也就是只要第一個(gè)參數(shù)相同,就采用緩存值)
let c = (a, b) => k++; let mem_c = mem(c); mem_c(1, 2); console.log(k);//1 mem_c(1, 3); console.log(k);//2 mem_c(1, 3); console.log(k);//2 let d = (a, b) => l++; let mem_d = mem(d, {cacheKey: x => JSON.stringify(x)}); mem_d(1, 2); console.log(l);//1 mem_d(1, 3); console.log(l);//1 mem_d(2, 3); console.log(l);//2
cache:設(shè)置緩存方式,默認(rèn)new Map(),例如.has(key), .get(key), .set(key, value), .delete(key), and optionally .clear(). You could for example use a WeakMap instead or quick-lru for a LRU cache.
cachePromiseRejection:緩存promise的reject的返回,默認(rèn)為false
mem.clear(fn):清除某個(gè)函數(shù)的緩存數(shù)據(jù)
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/53356.html
摘要:地址用于通過緩存具有相同輸入的調(diào)用結(jié)果來加速連續(xù)函數(shù)調(diào)用的優(yōu)化普通用法支持基于的異步函數(shù)調(diào)用第二參數(shù)用法用法設(shè)置緩存時(shí)長(zhǎng),默認(rèn)默認(rèn)所有參數(shù)相同才啟用緩存數(shù)據(jù),但你也可以設(shè)置只緩存第一個(gè)參數(shù)也就是只要第一個(gè)參數(shù)相同,就采用緩存值設(shè)置緩存方式, [github地址:https://github.com/ABCDdouyae...] mem 用于通過緩存具有相同輸入的調(diào)用結(jié)果來加速連續(xù)函數(shù)調(diào)...
摘要:地址用于通過緩存具有相同輸入的調(diào)用結(jié)果來加速連續(xù)函數(shù)調(diào)用的優(yōu)化普通用法支持基于的異步函數(shù)調(diào)用第二參數(shù)用法用法設(shè)置緩存時(shí)長(zhǎng),默認(rèn)默認(rèn)所有參數(shù)相同才啟用緩存數(shù)據(jù),但你也可以設(shè)置只緩存第一個(gè)參數(shù)也就是只要第一個(gè)參數(shù)相同,就采用緩存值設(shè)置緩存方式, [github地址:https://github.com/ABCDdouyae...] mem 用于通過緩存具有相同輸入的調(diào)用結(jié)果來加速連續(xù)函數(shù)調(diào)...
摘要:?jiǎn)栴}中如何將在十進(jìn)制和二八十六進(jìn)制之間互相轉(zhuǎn)換解決方案十進(jìn)制向二八十六進(jìn)制轉(zhuǎn)換分別使用這樣轉(zhuǎn)換會(huì)有一個(gè)前綴,如果不想要前綴只想要數(shù)值的話,可以使用二八十六進(jìn)制向十進(jìn)制轉(zhuǎn)換直接使用即可,因?yàn)榈脑褪?,所以我們只需要指定就行了討論如果只是需要? 問題 Python中如何將int在十進(jìn)制和二、八、十六進(jìn)制之間互相轉(zhuǎn)換 解決方案 十進(jìn)制向二、八、十六進(jìn)制轉(zhuǎn)換 分別使用bin、oct、hex >...
摘要:地址源碼依賴一個(gè)對(duì)象的屬性繼承另一個(gè)對(duì)象的屬性及其屬性描述符用法繼承者,被繼承者是否繼承者有該屬性的時(shí)候繼承默認(rèn)不繼承返回繼承后的新的對(duì)象當(dāng)?shù)谌齻€(gè)參數(shù)為時(shí)候,原對(duì)象又該屬性則沒有繼承被繼承者的屬性和屬性描述符 [github地址:https://github.com/ABCDdouyae...] merge-descriptors (express源碼依賴) 一個(gè)對(duì)象的屬性繼承另一個(gè)對(duì)...
閱讀 3481·2021-11-25 09:43
閱讀 2631·2021-09-22 15:54
閱讀 608·2019-08-30 15:55
閱讀 985·2019-08-30 15:55
閱讀 2010·2019-08-30 15:55
閱讀 1755·2019-08-30 15:53
閱讀 3481·2019-08-30 15:52
閱讀 2052·2019-08-30 12:55