npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-in-memory-cache

v1.0.12

Published

a nodejs implementations on how redis work

Downloads

59

Readme

node-in-memory-cache

node in memory cache is a lightweight Node.js package that provides a Redis-like caching system, offering persistent key-value storage with optional expiration times. It simplifies the management of strings, lists, sets, and hashes, all stored persistently on disk.

Features

  • String Operations: Set and retrieve string values with optional expiration times.
  • List Operations: Push and pop elements from lists at the front or back.
  • Set Operations: Add, remove, and list members of sets.
  • Hash Operations: Store, retrieve, and delete fields within hashes.
  • Persistent Storage: Automatically saves data to disk for durability across sessions.
  • Expiration: Supports setting expiration times for keys.

Installation

Install via npm:

npm install node-in-memory-cache

Usage

import {nodejsCache} from 'node-in-memory-cache'

String Operations

SET_STRING

Sets a string value with an optional expiration time.

nodejsCache.set_string('key1', 'value1', '60'); // Set 'key1' with value 'value1' and expiration time of 60 seconds

GET_STRING

Retrieves a string value based on the key.

const value = nodejsCache.get_string('key1'); // Retrieve value of 'key1'
console.log(value); // Outputs: 'value1' or 'nil' if expired or not found

List Operations

LIST_PUSH_FRONT

Pushes an element to the front of a list.

nodejsCache.list_push_front('myList', 'value2'); // Push 'value2' to the front of 'myList'

LIST_PUSH_BACK

Pushes an element to the back of a list.

nodejsCache.list_push_back('myList', 'value3'); // Push 'value3' to the back of 'myList'

LIST_POP_FRONT

Pops an element from the front of a list.

const poppedValue = nodejsCache.list_pop_front('myList'); // Pop from the front of 'myList'
console.log(poppedValue); // Outputs: 'value2' or 'nil' if list is empty

LIST_POP_BACK

Pops an element from the back of a list.

const poppedValue = nodejsCache.list_pop_back('myList'); // Pop from the back of 'myList'
console.log(poppedValue); // Outputs: 'value3' or 'nil' if list is empty

Set Operations

SET_ADD

Adds an element to a set.

nodejsCache.set_add('mySet', 'value4'); // Add 'value4' to 'mySet'

SET_REMOVE

Removes an element from a set.

nodejsCache.set_remove('mySet', 'value4'); // Remove 'value4' from 'mySet'

SET_MEMBERS

Retrieves all members of a set.

const setMembers = nodejsCache.set_members('mySet'); // Retrieve members of 'mySet'
console.log(setMembers);

Hash Operations

HASH_SET_FIELD

Sets a field within a hash.

nodejsCache.hash_set_field('myHash', 'field1', 'value5'); // Set 'field1' with 'value5' in 'myHash'

HASH_GET_FIELD

Retrieves the value of a field within a hash.

const hashValue = nodejsCache.hash_get_field('myHash', 'field1'); // Retrieve value of 'field1' in 'myHash'
console.log(hashValue);

HASH_DELETE_FIELD

Deletes a field from a hash.

nodejsCache.hash_delete_field('myHash', 'field1'); // Delete 'field1' from 'myHash'

HASH_GET_ALL

Retrieves all fields and values from a hash.

const allFields = nodejsCache.hash_get_all('myHash'); // Retrieve all fields and values from 'myHash'
console.log(allFields);

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.

License

This project is licensed under the MIT License. See the LICENSE file for more details.