在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:ImmortalDB开源软件地址:https://gitee.com/mirrors/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
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
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. APISetImmortalDB's API is simple. To store a value, use import { ImmortalDB } from 'immortal-db'await ImmortalDB.set('key', 'value')
const countPlusOne = (await ImmortalDB.set('count', numberOfClowns)) + 1 GetTo retrieve a value, use const value = await ImmortalDB.get('key', default=null)
RemoveFinally, to remove a key, use ImmortalDB.set('hi', 'bonjour')console.log(await ImmortalDB.get('hi')) // Prints 'bonjour'.await ImmortalDB.remove('hi')console.log(await ImmortalDB.get('hi')) // Prints 'null'.
Data StoresThe 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
Other, optional stores are:
New storage implementations can easily be added, too; they need onlyimplement the async methods InstallationInstalling ImmortalDB with npm is easy. $ npm install immortal-db Or include <html> <head> <script src="immortal-db.min.js"></script> <script> ;(async () => { const db = ImmortalDB.ImmortalDB await db.set('hi', 'lolsup') })() </script> </head> ...</html> DevelopmentTo 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 npm run build |
请发表评论