# reminisce

> Simple Node.js caching module with promises.

Latest version **0.1.0** (published 2016-08-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install reminisce
pnpm add reminisce
yarn add reminisce
bun add reminisce
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2016-08-24 |
| First published | 2016-08-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | ^4.0.0 |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Oscar Paramo |
| Maintainers | oparamo |
| Keywords | cache, caching, reminisce |

## Links

- npm: https://www.npmjs.com/package/reminisce
- Repository: https://github.com/oparamo/reminisce
- Homepage: https://github.com/oparamo/reminisce#readme
- Issues: https://github.com/oparamo/reminisce/issues
- npm.io page: https://npm.io/package/reminisce

## Dependencies (1)

- [bluebird](https://npm.io/package/bluebird.md) 3.4.1

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2016-08-24

## README

# reminisce
Simple Node.js caching module with promises.

## Installation
```javascript
npm i --save reminisce
```

## Example Usage
```javascript
const Reminisce = require('reminisce');
const cache = new Reminisce();

return cache.set({ key: 'example', value: 1, ttl: 10000 })
  // a 10ms delay just for example purposes
  .delay(10);
  .then(() => cache.get('example'))
  .spread((memory) => {
    // memory = { key: 'example', value: 1, expires: timestamp, lifespan: 10000, ttl: 9990 }
  });
```

## Options
An options object can be passed in when creating a new reminisce instance like so:
```javascript
const cache = new Reminisce({ memories: [], ttl: 60000 });
```
- `memories` (default: `[]`) can be a single memory object or an array of memory objects that will be stored
- `ttl` (default: `60000`) the default `ttl` for memories before they are forgotten (in milliseconds)

## Memories
When passing memory objects to the different reminisce functions, they should look like this:
```javascript
{
  key: 'example', // the String to use as a key that can be used to reference this memory later
  value: 1,       // the value being stored in memory
  ttl: 10000      // (optional) the time to live for a memory before it is forgotten (in milliseconds)
}
```
The `ttl` property is optional and will default to the `ttl` used when reminisce was initialized.

When memory objects are returned they will have `key`, `value`, and the following properties:
- `ttl` the *remaining* time to live for the memory before it is forgotten (in milliseconds)
- `expires` a UTC timestamp for when the memory is scheduled to be forgotten
- `lifespan` how long the memory was intended to live when it was created (in milliseconds)

## Get memories
```javascript
return cache.get('someKey')
  .spread((memory) => {
    // memory = { key: 'example', value: 1, expires: timestamp, lifespan: 10000, ttl: 9990 }
  });

return cache.get('forgottenKey')
  .spread((memory) => {
    // memory = undefined
  });

return cache.get([ 'someKey', 'someOtherKey', 'forgottenKey' ])
  .then((memories) => {
    // memories = [{ someMemory }, { someOtherMemory }, undefined]
  });
```
Takes a String `key` or an array of `key`'s, returns a promise that resolves to an array of memory objects. If a memory isn't associated with a given key, `undefined` will be returned in its place.

## Set memories
```javascript
return cache.set({ key: 'someKey', value: 1, ttl: 10000 })
  .spread((memory) => {
    // memory = { key: 'example', value: 1, expires: timestamp, lifespan: 10000, ttl: 10000 }
  });

const cache = new Reminisce({ ttl: 60000 });
return cache.set({ key: 'someKey', value: 1 })
  .spread((memory) => {
    // memory = { key: 'example', value: 1, expires: timestamp, lifespan: 60000, ttl: 60000 }
  });

return cache.set([{ someMemory }, { someOtherMemory }])
  .then((memories) => {
    // memories = [{ someMemory }, { someOtherMemory }]
  });
```
Takes a memory object or an array of memory objects, returns a promise that resolves to an array of memory objects. If there is already a memory associated with a given key, then this function will override that memory.

## Update memories
```javascript
const cache = new Reminisce({
  memories: { key: 'existingKey', value: 2, ttl: 30000 }
});
return cache.update({ key: 'existingKey', value: 5 })
  .spread((memory) => {
    // memory = { key: 'existingKey', value: 5, expires: timestamp, lifespan: 30000, ttl: unaffectedRemainingTTL }
  });

const cache = new Reminisce({
  memories: [{ key: 'existingKey', value: 5, ttl: 30000 }, { key: 'otherExistingKey', value: 6 }]
});
return cache.update([{ key: 'existingKey', value: 7 }, { key: 'otherExistingKey', value: 8 }])
  .then((memories) => {
  /*
    memories = [{
      key: 'existingKey',
      value: 7,
      expires: timestamp,
      lifespan: 30000,
      ttl: unaffectedRemainingTTL
    }, {
      key: 'otherExistingKey',
      value: 8,
      expires: timestamp,
      lifespan: 60000,
      ttl: unaffectedRemainingTTL
    }]
  */
  });

return cache.update({ forgottenMemory })
  .spread((memory) => {
    // memory = undefined
  });
```
Takes a memory object or an array of memory objects, returns a promise that resolves to an array of memory objects. If a memory isn't associated with a given key, `undefined` will be returned in its place. This function can be used to update memory `value`s without changing when memories are scheduled to be forgotten.


## Delete memories
```javascript
return cache.delete('someKey')
  .then((result) => {
    // result = true
  });

return cache.delete('forgottenKey')
  .then((result) => {
    // result = true
  });

return cache.delete([ 'someKey', 'someOtherKey', 'forgottenKey' ])
  .then((result) => {
    // result = true
  });
```
Takes a String `key` or an array of `key`'s, returns a promise that resolves to `true` if deletions were successful. If a memory isn't associated with a given key, a promise that resolves to `true` will still be returned.

## Flush memories
```javascript
return cache.flush()
  .then((result) => {
    // result = true
  });
```
Flushes all memories and returns a promise that resolves to `true` if successful.

## Keys
```javascript
const cache = new Reminisce({
  memories: [{ key: 'someKey', ... }, { key: 'someOtherKey', ... }]
});
console.log(cache.keys);
// -> [ 'someKey', 'someOtherKey' ]
```
Returns an array of keys associated with current memories.

---
_Source: https://npm.io/package/reminisce · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
