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 🙏

© 2026 – Pkg Stats / Ryan Hefner

graphwork-cache

v2.0.1

Published

Cache management for GraphWork Framework 2.0

Readme

Cache

Cache management for GraphWork Framework 2.0

Overview

The Cache module provides efficient caching mechanisms for the GraphWork Framework. It includes implementations of LRU (Least Recently Used) cache and memory cache to optimize performance and reduce redundant computations.

Installation

npm install graphwork-cache

Features

  • LRU Cache: Implements Least Recently Used eviction policy
  • Memory Cache: Simple in-memory caching solution
  • TTL Support: Time-to-live expiration for cached items
  • Performance Optimized: Efficient memory usage and fast access times
  • TypeScript Support: Full TypeScript definitions included

Usage

LRU Cache

import { LRUCache } from 'graphwork-cache';

// Create an LRU cache with a maximum size of 100 items
const cache = new LRUCache<string>({
  maxSize: 100,
  ttl: 3600000 // 1 hour in milliseconds
});

// Set a value
cache.set('key1', 'value1');

// Get a value
const value = cache.get('key1');

// Check if a key exists
const exists = cache.has('key1');

// Delete a key
cache.delete('key1');

// Clear all entries
cache.clear();

Memory Cache

import { MemoryCache } from 'graphwork-cache';

// Create a memory cache
const cache = new MemoryCache<string>({
  ttl: 1800000 // 30 minutes in milliseconds
});

// Set a value
cache.set('key1', 'value1');

// Get a value
const value = cache.get('key1');

Cache Manager

import { CacheManager } from 'graphwork-cache';

// Create a cache manager
const cacheManager = new CacheManager({
  maxSize: 1000
});

// Create different cache instances
const userCache = cacheManager.createLRUCache<User>('users');
const productCache = cacheManager.createMemoryCache<Product>('products');

// Use caches
userCache.set('user1', { id: 'user1', name: 'John Doe' });
const user = userCache.get('user1');

API

LRUCache

Constructor

new LRUCache<T>(config: CacheConfig)

Methods

  • set(key: string, value: T): void - Sets a value in the cache
  • get(key: string): T | undefined - Gets a value from the cache
  • has(key: string): boolean - Checks if a key exists in the cache
  • delete(key: string): boolean - Deletes a key from the cache
  • clear(): void - Clears all entries from the cache
  • size(): number - Returns the number of entries in the cache
  • maxSize(): number - Returns the maximum size of the cache

MemoryCache

Constructor

new MemoryCache<T>(config: CacheConfig)

Methods

  • set(key: string, value: T): void - Sets a value in the cache
  • get(key: string): T | undefined - Gets a value from the cache
  • has(key: string): boolean - Checks if a key exists in the cache
  • delete(key: string): boolean - Deletes a key from the cache
  • clear(): void - Clears all entries from the cache
  • size(): number - Returns the number of entries in the cache

CacheManager

Constructor

new CacheManager(config: CacheManagerConfig)

Methods

  • createLRUCache<T>(name: string, config?: CacheConfig): LRUCache<T> - Creates a new LRU cache
  • createMemoryCache<T>(name: string, config?: CacheConfig): MemoryCache<T> - Creates a new memory cache
  • getCache(name: string): Cache | undefined - Gets a cache by name
  • deleteCache(name: string): boolean - Deletes a cache by name
  • clearAll(): void - Clears all caches
  • getAllStats(): Record<string, CacheStats> - Gets statistics for all caches

Configuration

CacheConfig

interface CacheConfig {
  maxSize?: number;    // Maximum number of items (for LRU cache)
  ttl?: number;        // Time to live in milliseconds
}

CacheManagerConfig

interface CacheManagerConfig {
  maxSize?: number;    // Default maximum size for caches
}

Performance

The cache implementations are optimized for:

  • Fast O(1) access times
  • Efficient memory usage
  • Automatic cleanup of expired entries
  • Minimal garbage collection overhead

Contributing

See our Contributing Guide for information on how to contribute to this package.

License

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