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