-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathdeno_memoize.deno.txt
29 lines (25 loc) · 1.69 KB
/
deno_memoize.deno.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
┏━━━━━━━━━━━━━━━━━━┓
┃ DENO_MEMOIZE ┃
┗━━━━━━━━━━━━━━━━━━┛
ALTERNATIVES ==> #See moize
VERSION ==> #Part of Deno
#Browser compatible
@std/cache/memoize !#
memoize(FUNC[, OPTS])->FUNC2 #Returns memoized FUNC
#Does not cache if FUNC throws
#If async, PROMISE is initially cached, but then removed if it is rejected
OPTS.getKey #FUNC(...ARGS)->VAL computing cache key
#Def:
# - undefined|null|BOOL|NUM -> String()
# - STR -> '"..."'
# - BIGINT -> 'NUMn'
# - SYM -> 'Symbol.for(SYM.description)'
# - OBJ|ARR -> '{UINT}'
# - incremented from 0, for a given FUNC2
# - each UINT represents a specific identity
# - i.e. as if a WeakMap was used
# - but actually use a FinalizationRegistry under-the-hood
# - if several args, joined by ,
OPTS.cache #MAP (only get|set|has|delete() needed) (def: new Map()) storing results
#E.g. can use deno LRU cache (see its doc)
FUNC.length|name #Are kept