StorageLRU LRU 缓存实现

程序名称:StorageLRU

授权协议: BSD

操作系统: 跨平台

开发语言: JavaScript

StorageLRU 介绍

StorageLRU(storage-lru) 是 LRU 缓存实现,可以用在本地存储或者其他存储机制,支持一个类似的接口。

注意: 这个库是使用 CommonJS 风格编写的,如果要在浏览器使用,需要使用
Browserify
Webpack 类似的工具。

主要特性:

  • 可插拔的离线存储

  • 统计数据

  • 自定义的 PurgeComparator

  • 优先级

  • 自动清理

使用:

var StorageLRU = require('storage-lru').StorageLRU;
var asyncify = require('storage-lru').asyncify;
var lru = new StorageLRU(asyncify(localStorage), {
    purgeFactor: 0.5,  // this controls amount of extra space to purge.
    purgedFn: function (purgedKeys) {
        console.log('These keys were purged:', purgedKeys);
    }
});
console.log(lru.numItems()); // output 0, assuming the storage is clear
lru.setItem('foo', 'bar', {}, function (err) {
    if (err) {
        // something went wrong. Item not saved.
        console.log('Failed to save item: err=', err);
    }
});
lru.setItem('fooJSON', {foo: 'bar'}, {json: true}, function (err) {
    if (err) {
        // something went wrong. Item not saved.
        console.log('Failed to save item: err=', err);
    }
});
lru.getItem('foo', {json: false}, function (err, value) {
    if (err) {
        // something went wrong, for example, can't deserialize
        console.log('Failed to fetch item: err=', err);
        return;
    }
    console.log('The value of "foo" is: ', value);
});
lru.removeItem('foo', function (err) {
    if (err) {
        // something went wrong. Item not removed.
    }
});
var stats = lru.stats();

StorageLRU 官网

https://github.com/yahoo/storage-lru

相关编程语言

BlazeDS 是一个基于服务器的Java 远程控制(remoting...
OVal 是一个可扩展的Java对象数据验证框架,验证的规...
Volta 是一套开发工具,专为开发分布式、实时系统应...
OpenDDS 是一个开源的 C++ 实现的 对象管理组织 OMG...
JADE (Java Agent DEvelopment Framework) 是一个完...
FastMM ,在D2006和2007中已代替了原来的内存管理器。