Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "keyv", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Simple key-value storage with support for multiple backends", | ||
@@ -47,4 +47,5 @@ "main": "src/index.js", | ||
"this": "^1.0.2", | ||
"timekeeper": "^1.0.0", | ||
"xo": "^0.19.0" | ||
} | ||
} |
@@ -13,10 +13,10 @@ <h1 align="center"> | ||
Keyv provides a consistent interface for key-value storage across multiple backends via storage adapters. Supports TTL based expiry making it suitable as a cache or a persistent key-value store. | ||
Keyv provides a consistent interface for key-value storage across multiple backends via storage adapters. It supports TTL based expiry, making it suitable as a cache or a persistent key-value store. | ||
## Features | ||
There are a few existing modules similar to Keyv, however none of them fulfilled all of my requirements. I created Keyv because I wanted something that: | ||
There are a few existing modules similar to Keyv, however Keyv is different because it: | ||
- Wasn't bloated | ||
- Had a simple Promise based API | ||
- Isn't bloated | ||
- Has a simple Promise based API | ||
- Suitable as a TTL based cache or persistent key-value store | ||
@@ -130,3 +130,3 @@ - [Easily embeddable](#add-cache-support-to-your-module) inside another module | ||
Keyv is designed to be easily embedded into other modules to add cache support. The recommended pattern is to expose a `cache` option in your modules options which is passed through to Keyv. Caching will work in memory by default and users have the option to also install a Keyv storage adapter and pass in a connection string. | ||
Keyv is designed to be easily embedded into other modules to add cache support. The recommended pattern is to expose a `cache` option in your modules options which is passed through to Keyv. Caching will work in memory by default and users have the option to also install a Keyv storage adapter and pass in a connection string, or any other storage that implements the `Map` API. | ||
@@ -155,2 +155,5 @@ You should also set a namespace for your module so you can safely call `.clear()` without clearing unrelated app data. | ||
const awesomeModule = new AwesomeModule({ cache: 'redis://localhost' }); | ||
// Some third-party module that implements the Map API | ||
const awesomeModule = new AwesomeModule({ cache: some3rdPartyStore }); | ||
``` | ||
@@ -157,0 +160,0 @@ |
import test from 'ava'; | ||
import delay from 'delay'; | ||
import tk from 'timekeeper'; | ||
import keyvTestSuite from 'keyv-test-suite'; | ||
import Keyv from 'this'; | ||
test('Keyv is a class', t => { | ||
test.serial('Keyv is a class', t => { | ||
t.is(typeof Keyv, 'function'); | ||
@@ -12,3 +12,3 @@ t.throws(() => Keyv()); // eslint-disable-line new-cap | ||
test('Keyv accepts storage adapters', async t => { | ||
test.serial('Keyv accepts storage adapters', async t => { | ||
const store = new Map(); | ||
@@ -22,3 +22,3 @@ const keyv = new Keyv({ store }); | ||
test('Keyv hands tll functionality over to ttl supporting stores', async t => { | ||
test.serial('Keyv hands tll functionality over to ttl supporting stores', async t => { | ||
t.plan(3); | ||
@@ -35,7 +35,8 @@ const store = new Map(); | ||
t.is(await keyv.get('foo'), 'bar'); | ||
await delay(150); | ||
tk.freeze(Date.now() + 150); | ||
t.is(await keyv.get('foo'), 'bar'); | ||
tk.reset(); | ||
}); | ||
test('Keyv respects default tll option', async t => { | ||
test.serial('Keyv respects default tll option', async t => { | ||
const store = new Map(); | ||
@@ -45,7 +46,10 @@ const keyv = new Keyv({ store, ttl: 100 }); | ||
t.is(await keyv.get('foo'), 'bar'); | ||
await delay(150); | ||
tk.freeze(Date.now() + 150); | ||
t.is(await keyv.get('foo'), undefined); | ||
tk.reset(); | ||
}); | ||
test('.set(key, val, ttl) overwrites default tll option', async t => { | ||
test.serial('.set(key, val, ttl) overwrites default tll option', async t => { | ||
const startTime = Date.now(); | ||
tk.freeze(startTime); | ||
const store = new Map(); | ||
@@ -59,11 +63,12 @@ const keyv = new Keyv({ store, ttl: 200 }); | ||
t.is(await keyv.get('ping'), 'pong'); | ||
await delay(150); | ||
tk.freeze(startTime + 150); | ||
t.is(await keyv.get('foo'), 'bar'); | ||
t.is(await keyv.get('fizz'), undefined); | ||
t.is(await keyv.get('ping'), 'pong'); | ||
await delay(100); | ||
tk.freeze(startTime + 250); | ||
t.is(await keyv.get('foo'), undefined); | ||
t.is(await keyv.get('ping'), 'pong'); | ||
await delay(100); | ||
tk.freeze(startTime + 350); | ||
t.is(await keyv.get('ping'), undefined); | ||
tk.reset(); | ||
}); | ||
@@ -70,0 +75,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19883
180
240
14