• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ImmortalDB: ImmortalDB 是用于浏览器的弹性键值存储 ImmortalDB 是在浏览器中存储持 ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

ImmortalDB

开源软件地址:

https://gitee.com/mirrors/immortaldb

开源软件介绍:

ImmortalDB

ImmortalDB

ImmortalDB is a resilient key-value store for the browser.

ImmortalDB is the best way to store persistent key-value data in thebrowser. Data saved to ImmortalDB is redundantly stored inCookies,IndexedDB, andLocalStorage,and relentlessly self heals if any data therein is deleted or corrupted.

For example, clearing cookies is a common user action, even for non-technicalusers. And browsers unceremoniouslydeleteIndexedDB, LocalStorage, and/or SessionStorage without warning under storagepressure.

ImmortalDB is resilient in the face of such events.

In this way, ImmortalDB is likeEvercookie, but

  1. Is actively maintained and well documented.

  2. Provides a simple, modern, Promise-based API.

  3. Strikes an equitable balance between reliability and respect for theuser. Data is stored reliably but can also be voluntarily purged if theuser designedly clears cookies and application storage.

  4. Doesn't use nefarious exploits nor deprecated third party plugins likeFlash, Silverlight, or Java. Only standard, ratified HTML5 APIs are used.

  5. Doesn't vandalize performance or the user experience. For example,Evercookie's CSS History Knocking can beget a deluge of background HTTPrequests, and loading Silverlight or Flash can raise unsought permissionmodals or thrash the user's disk.

How ImmortalDB works.

When you store a key-value pair in ImmortalDB, that key and value aresaved redundantly in the browser's cookies, IndexedDB, and LocalStoragedata stores.

When a value is retrieved via its key, ImmortalDB

  1. Looks up that key in every data store.
  2. Counts each unique returned value.
  3. Determines the most commonly returned unique value as the 'correct' value.
  4. Returns this correct value.

Then ImmortalDB self-heals: if any data store(s) returned a value different thanthe determined correct value, or no value at all, the correct value is rewrittento that store. In this way, consensus, reliability, and redundancy ismaintained.

API

Set

ImmortalDB's API is simple. To store a value, use set(key, value):

import { ImmortalDB } from 'immortal-db'await ImmortalDB.set('key', 'value')

key and value must beDOMStrings.ImmortalDB.set(key, value) also always returns value, so it can be chained orembedded, like

const countPlusOne = (await ImmortalDB.set('count', numberOfClowns)) + 1

Get

To retrieve a value, use get(key, default=null):

const value = await ImmortalDB.get('key', default=null)

get() returns the value associated with key, if key exists. If keydoesn't exist, default is returned. key must be aDOMString.

Remove

Finally, to remove a key, use remove(key):

ImmortalDB.set('hi', 'bonjour')console.log(await ImmortalDB.get('hi'))  // Prints 'bonjour'.await ImmortalDB.remove('hi')console.log(await ImmortalDB.get('hi'))  // Prints 'null'.

key must be aDOMString.

Data Stores

The data stores that ImmortalDB stores data in can also be configured.For example, this is how to store data reliably in cookies andLocalStorage only:

import { ImmortalStorage, CookieStore, LocalStorageStore } from 'immortal-db'const stores = [await CookieStore(), await LocalStorageStore()]const db = new ImmortalStorage(stores)await db.set(key, JSON.stringify({1:1}))

By default, stores used by ImmortalDB are:

  • CookieStore -> Keys and values are stored in document.cookie.
  • IndexedDbStore -> Keys and values are stored in window.indexedDB.
  • LocalStorageStore -> Keys and values are stored in window.localStorage.

Other, optional stores are:

  • SessionStorageStore -> Keys and values are stored in window.sessionStorage.

New storage implementations can easily be added, too; they need onlyimplement the async methods get(key, default), set(key, value), andremove(key).

Installation

Installing ImmortalDB with npm is easy.

$ npm install immortal-db

Or include dist/immortal-db[.min].js and use window.ImmortalDB directly.

<html>  <head>    <script src="immortal-db.min.js"></script>    <script>      ;(async () => {        const db = ImmortalDB.ImmortalDB        await db.set('hi', 'lolsup')      })()    </script>  </head>  ...</html>

Development

To test ImmortalDB, run

npm run start

This starts a webpack dev server and opensImmortalDB's testing website,http://localhost:9234/.

Once tested, to produce new production-ready files immortal-db.js andimmortal-db.min.js in dist/, run

npm run build

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap