This repository was archived by the owner on Mar 10, 2020. It is now read-only.
File tree 2 files changed +20
-1
lines changed 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change 28
28
"ipfs-merkle-dag" : " ^0.7.1" ,
29
29
"is-ipfs" : " ^0.2.0" ,
30
30
"isstream" : " ^0.1.2" ,
31
+ "lru-cache" : " ^4.0.1" ,
31
32
"multiaddr" : " ^2.0.2" ,
32
33
"multipart-stream" : " ^2.0.1" ,
33
34
"ndjson" : " ^1.4.3" ,
103
104
"url" : " https://github.com/ipfs/js-ipfs-api/issues"
104
105
},
105
106
"homepage" : " https://github.com/ipfs/js-ipfs-api"
106
- }
107
+ }
Original file line number Diff line number Diff line change @@ -6,6 +6,12 @@ const promisify = require('promisify-es6')
6
6
const bs58 = require ( 'bs58' )
7
7
const bl = require ( 'bl' )
8
8
const cleanMultihash = require ( '../clean-multihash' )
9
+ const LRU = require ( 'lru-cache' )
10
+ const lruOptions = {
11
+ max : 128
12
+ }
13
+
14
+ const cache = LRU ( lruOptions )
9
15
10
16
module . exports = ( send ) => {
11
17
const api = {
@@ -14,6 +20,7 @@ module.exports = (send) => {
14
20
callback = options
15
21
options = { }
16
22
}
23
+
17
24
if ( ! options ) {
18
25
options = { }
19
26
}
@@ -24,6 +31,12 @@ module.exports = (send) => {
24
31
return callback ( err )
25
32
}
26
33
34
+ const node = cache . get ( multihash )
35
+
36
+ if ( node ) {
37
+ return callback ( null , node )
38
+ }
39
+
27
40
send ( {
28
41
path : 'object/get' ,
29
42
args : multihash
@@ -37,9 +50,12 @@ module.exports = (send) => {
37
50
return new DAGLink ( l . Name , l . Size , new Buffer ( bs58 . decode ( l . Hash ) ) )
38
51
} ) )
39
52
53
+ cache . set ( multihash , node )
54
+
40
55
callback ( null , node )
41
56
} )
42
57
} ) ,
58
+
43
59
put : promisify ( ( obj , options , callback ) => {
44
60
if ( typeof options === 'function' ) {
45
61
callback = options
@@ -107,6 +123,8 @@ module.exports = (send) => {
107
123
return callback ( new Error ( 'Stored object was different from constructed object' ) )
108
124
}
109
125
126
+ cache . set ( result . Hash , node )
127
+
110
128
callback ( null , node )
111
129
} )
112
130
} ) ,
You can’t perform that action at this time.
0 commit comments