包详细信息

cachimo

svipben304MIT不推荐使用2.0.4

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

Stores key with value in-memory and can be deleted manually or after given timeout.

cache, in-memory, storage, nodejs

自述文件

cachimo · npm Build Status

Stores key with value in-memory and can be deleted manually or after given timeout.

Installation

npm

npm install cachimo

Yarn

yarn add cachimo

Usage

API

  • put
import * as cachimo from "cachimo";

// Stores element in cache, you can remove it manually whenever you want.
// Returns true if element was successfully stored in cache, false if such key already exist.
cachimo.put("key", "value");
import * as cachimo from "cachimo";

// Stores element in cache and it will be deleted after given timeout which returns Promise.
cachimo
    .put("key", "value", 1000) // It will be deleted after 1 sec. and Promise will be resolved or rejected.
    .then(({ key, value, timeout }) => {
        // Returns key, value and timeout after delete.
        console.log(`Deleted ${key}:${value} after ${timeout}`);
    })
    .catch((err) => {
        // You will get error if key was deleted before timeout.
        throw err; // "Key doesn't exist."
    });
import * as cachimo from "cachimo";

// If you don't want to use Promise you can send callback which will be executed after given timeout.
cachimo.put("key", "value", 1000, (err, key, value, timeout) => {
    // You will get error if key was deleted before timeout.
    if (err) {
        throw err; // "Key doesn't exist."
    }

    // Returns key, value and timeout after delete.
    console.log(`Deleted ${key}:${value} after ${timeout}`);
});
  • clear
import * as cachimo from "cachimo";

// Removes all elements stored in cache and clears all timeouts.
// Returns number of how much elements was removed from cache.
cachimo.clear();
  • get
import * as cachimo from "cachimo";

// Returns value from cache by given key.
cachimo.get("key");
  • remove
import * as cachimo from "cachimo";

// Returns true if element was removed, false otherwise.
cachimo.remove("key");
  • has
import * as cachimo from "cachimo";

// Checks if whether an element with given key exists.
// Returns true if element exists, false otherwise.
cachimo.has("key");
  • size
import * as cachimo from "cachimo";

// Returns the number of elements stored in cache.
cachimo.size();
  • keys
import * as cachimo from "cachimo";

// Returns all keys stored in cache.
cachimo.keys();
  • values
import * as cachimo from "cachimo";

// Returns all values stored in cache.
cachimo.values();
  • entries
import * as cachimo from "cachimo";

// Returns all entries (keys and values) stored in cache.
cachimo.entries();

Contributing

Feel free to open issues or PRs!

更新日志

[Unreleased]

2.0.4 (July 7, 2020)

  • Update all dependencies.

2.0.3 (June 25, 2020)

  • Update all dependencies.

2.0.2 (May 17, 2020)

  • Reformat project with new settings.
  • Update all dependencies.

2.0.1 (May 2, 2020)

  • Generate declaration file and include it in the package.json.

2.0.0 (May 2, 2020)

  • Change indentation to tabs.
  • Update all dependencies and add TypeScript.
  • Drop ESLint.
  • Replace CircleCI to Azure Pipelines.
  • Rewrite everything to TypeScript.

1.0.7 (August 3, 2019)

  • Update all dependencies.
  • Fix ESLint error in tests.

1.0.6 (2018-04-15)

Added

  • jsconfig.json file which represents project structure.
  • yarn-error.log in .gitignore.

Changed

  • ⬆️ ESLint to 4.19.1.
  • ⬆️ Jest to 22.4.3.

Removed

  • logo from README.md.

1.0.5 (2018-03-10)

  • Renamed index.d.ts to cachimo.d.ts and moved it to src dir.
  • Deleted index.js and changed main in package.json to the src/cachimo.js
  • Reduced logo width and height.
  • ⬆️ keywords in package.json
  • ⬆️ ESLint to 4.18.2
  • ⬆️ Jest to 22.4.2

1.0.4 (2018-02-17)

Added

  • typings property in package.json.

Changed

  • clear() function to also reject Promise or execute callback to inform if timeout was cleared.
  • README.md to show how new clear() function works.
  • Travis CI to also run ESLint before tests.
  • Travis CI to disable email notifications.
  • Tests to be more isolated.
  • Moved all index.js code to the src/cachimo.js.

Updated

  • ⬆️ ESLint to 4.18.0
  • ⬆️ Jest to 22.3.0

1.0.3 (2018-02-17)

Added

  • Travis CI.
  • Build status and NPM version badges in README.md.

Changed

  • clear() clears all timeouts as well. #1

1.0.2 (2018-02-07)

Added

  • CHANGELOG.md.
  • TypeScript declaration file (index.d.ts).

Changed

  • Minor change in put(...) JSDoc.
  • Error to TypeError in put(...).
  • Logo to the new one. 😊
  • package.json description to have dot at the end. 😑

1.0.1 (2018-02-01)

  • Initial release.