Re-add the LRU removal (higher-level) (#200)

This commit is contained in:
Jaco Greeff
2018-08-28 21:54:47 +02:00
committed by GitHub
parent e29f3fc964
commit 1654aa46fe
+10 -7
View File
@@ -5,13 +5,13 @@
import { DiskStore } from './types';
import { AbstractLevelDOWN } from 'abstract-leveldown';
import { LRUMap } from 'lru_map';
// import { LRUMap } from 'lru_map';
import isUndefined from '@polkadot/util/is/undefined';
import logger from '@polkadot/util/logger';
import Combined from './store/Combined';
const LRU_SIZE = 16384;
// const LRU_SIZE = 16384;
const KEY_LENGTH = 32;
const l = logger('disk/scatter');
@@ -20,13 +20,13 @@ const noop = () =>
class DiskDown extends AbstractLevelDOWN {
_disk: DiskStore;
_store: LRUMap<string, Buffer>;
// _store: LRUMap<string, Buffer>;
constructor (location: string) {
super(location);
this._disk = new Combined(location);
this._store = new LRUMap(LRU_SIZE);
// this._store = new LRUMap(LRU_SIZE);
}
compact (progress: (message: string) => void): void {
@@ -73,7 +73,7 @@ class DiskDown extends AbstractLevelDOWN {
_del (key: Buffer, options: any, callback: Function) {
l.debug(() => ['_del', key]);
this._store.delete(key.toString());
// this._store.delete(key.toString());
this._disk.delete(key);
process.nextTick(callback);
@@ -82,7 +82,10 @@ class DiskDown extends AbstractLevelDOWN {
_get (key: Buffer, options: any, callback: Function) {
l.debug(() => ['_get', key.toString('hex')]);
const value = this._store.get(key.toString()) || this._disk.get(key);
// FIXME _If_ LRU is re-instated, it needs to get set once a value is
// retrieved from disk. (As of now, not needed since removed)
// const value = this._store.get(key.toString()) || this._disk.get(key);
const value = this._disk.get(key);
if (isUndefined(value)) {
process.nextTick(callback, new Error('NotFound'));
@@ -95,7 +98,7 @@ class DiskDown extends AbstractLevelDOWN {
_put (key: Buffer, value: Buffer, options: any, callback: Function) {
l.debug(() => ['_put', key.toString('hex'), value]);
this._store.set(key.toString(), value);
// this._store.set(key.toString(), value);
this._disk.set(key, value);
process.nextTick(callback);