Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

Commit

Permalink
Convert Blockchain and Cache to es6, mv Cache to own file
Browse files Browse the repository at this point in the history
Signed-off-by: Sina Mahmoodi <itz.s1na@gmail.com>
  • Loading branch information
s1na committed Feb 11, 2019
1 parent 113c878 commit cf63226
Show file tree
Hide file tree
Showing 2 changed files with 948 additions and 949 deletions.
29 changes: 29 additions & 0 deletions src/cache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const LRU = require('lru-cache')

// Simple LRU Cache that allows for keys of type Buffer
module.exports = class Cache {
constructor (opts) {
this._cache = new LRU(opts)
}

set (key, value) {
if (key instanceof Buffer) {
key = key.toString('hex')
}
this._cache.set(key, value)
}

get (key) {
if (key instanceof Buffer) {
key = key.toString('hex')
}
return this._cache.get(key)
}

del (key) {
if (key instanceof Buffer) {
key = key.toString('hex')
}
this._cache.del(key)
}
}
Loading

0 comments on commit cf63226

Please sign in to comment.