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

@obi-tec/memory-cache

v1.0.6

Published

Memory Cache is a TypeScript library for caching data in memory to improve the performance of your applications.

Downloads

0

Readme

Memory Cache

Memory Cache is a TypeScript library for in-memory caching. It provides a simple and efficient way to store and retrieve data in memory, improving the performance of your applications.

Features

  • Lightweight and fast
  • Simple API
  • Supports TTL (Time to Live) for cache entries
  • Written in TypeScript for type safety

Installation

To install the library, use npm or yarn:

npm install @obi-tec/memory-cache

Usage

Here's a basic example of how to use Memory Cache TS:

import MemoryCache from '@obi-tec/memory-cache';

// Set a value in the cache
MemoryCache.set<number>('key', 123, 60); // The value will expire in 60 seconds

// Get a value from the cache
const value = MemoryCache.get('key');
console.log(value); // Output: 123

// Delete a value from the cache
MemoryCache.del('key');

API

set<T>(key: string, value: T, ttl?: number): void

Stores a value in the cache with an optional TTL (Time to Live).

  • key: The key to store the value under.
  • value: The value to store.
  • ttl: Optional. The time in seconds before the value expires. Default value is 60 seconds.

get<T>(key: string): T | undefined

Retrieves a value from the cache.

  • key: The key of the value to retrieve.
  • Returns: The value associated with the key, or undefined if the key does not exist in the cache.

del(key: string): void

Deletes a value from the cache.

  • key: The key of the value to delete.

flush(): void

Flushes the entire cache, removing all entries.

keys(): string[]

Returns an array of all keys currently stored in the cache.

getTTL(key: string): number | undefined

Retrieves the remaining TTL (Time to Live) for a given key.

  • key: The key of the value to check the TTL for.
  • Returns: The remaining TTL in seconds, or undefined if the key does not exist or has no TTL set.

setTTL(key: string, ttl: number): void

Updates the TTL (Time to Live) for an existing cache entry.

  • key: The key of the value to update the TTL for.
  • ttl: The new TTL in seconds.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

License

This project is licensed under the Apache License.