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

@teliagen/cache

v0.4.3

Published

Teliagen official caching system with tagging and decorators

Downloads

32

Readme

@teliagen/cache

Caching system for the Teliagen Framework.

npm version TypeScript License: Apache-2.0

Overview

@teliagen/cache provides a flexible caching solution:

  • In-Memory Cache – Fast default cache
  • TTL Support – Time-to-live expiration
  • Key Patterns – Wildcard key invalidation
  • Driver Interface – Extensible for Redis, etc.

Installation

npm install @teliagen/cache
# or
pnpm add @teliagen/cache

Quick Start

import { Cache } from '@teliagen/cache';

const cache = new Cache();

// Set a value
await cache.set('user:123', { name: 'Alice', email: '[email protected]' });

// Get a value
const user = await cache.get('user:123');

// Set with TTL (60 seconds)
await cache.set('session:abc', { userId: '123' }, 60);

// Delete
await cache.delete('user:123');

API Reference

Cache Class

class Cache {
  constructor(options?: CacheOptions);
  
  // Get value by key
  get<T>(key: string): Promise<T | null>;
  
  // Set value with optional TTL (seconds)
  set<T>(key: string, value: T, ttl?: number): Promise<void>;
  
  // Check if key exists
  has(key: string): Promise<boolean>;
  
  // Delete by key
  delete(key: string): Promise<boolean>;
  
  // Delete by pattern (e.g., 'user:*')
  deletePattern(pattern: string): Promise<number>;
  
  // Clear all cache
  clear(): Promise<void>;
  
  // Get or set (fetch if missing)
  getOrSet<T>(key: string, factory: () => T | Promise<T>, ttl?: number): Promise<T>;
}

Configuration

interface CacheOptions {
  // Default TTL in seconds (0 = no expiration)
  defaultTTL?: number;
  
  // Maximum cache size (items)
  maxSize?: number;
  
  // Cache driver
  driver?: CacheDriver;
}

const cache = new Cache({
  defaultTTL: 3600,  // 1 hour default
  maxSize: 10000
});

Usage Examples

Basic Caching

import { Cache } from '@teliagen/cache';

const cache = new Cache();

// Cache database query results
async function getUser(id: string) {
  const cacheKey = `user:${id}`;
  
  // Check cache first
  let user = await cache.get(cacheKey);
  
  if (!user) {
    // Fetch from database
    user = await User.findById(id);
    
    // Cache for 5 minutes
    await cache.set(cacheKey, user, 300);
  }
  
  return user;
}

Get Or Set Pattern

// Simpler version using getOrSet
async function getUser(id: string) {
  return cache.getOrSet(
    `user:${id}`,
    () => User.findById(id),
    300  // 5 minutes TTL
  );
}

Cache Invalidation

// Delete specific key
await cache.delete('user:123');

// Delete all user cache
await cache.deletePattern('user:*');

// Delete all cache
await cache.clear();

In Actions

import { Action, ActionProvider, Input } from '@teliagen/commons';
import { Cache } from '@teliagen/cache';

const cache = new Cache({ defaultTTL: 600 });

@ActionProvider('products', 'ProductActions')
class ProductActions {
  @Action('getProduct')
  async getProduct(@Input() input: { id: string }) {
    return cache.getOrSet(
      `product:${input.id}`,
      () => Product.findById(input.id)
    );
  }

  @Action('updateProduct')
  async updateProduct(@Input() input: UpdateProductInput) {
    const product = await Product.update(input.id, input);
    
    // Invalidate cache
    await cache.delete(`product:${input.id}`);
    await cache.deletePattern(`products:list:*`);
    
    return product;
  }
}

With Framework Feature

Use the Cache feature in your config:

// teliagen.config.ts
import { defineConfig, Cache } from '@teliagen/commons';

export default defineConfig({
  features: [
    Cache({
      enabled: true,
      ttl: 3600
    })
  ]
});

Then use @Cacheable decorator:

@ActionProvider('products', 'ProductActions')
class ProductActions {
  @Action('listProducts')
  @Cacheable({ ttl: 300, key: 'products:list:{page}' })
  async listProducts(@Input() input: { page: number }) {
    return Product.findAll({ offset: input.page * 20, limit: 20 });
  }
}

Custom Drivers

Redis Driver

import { Cache, CacheDriver } from '@teliagen/cache';
import Redis from 'ioredis';

class RedisDriver implements CacheDriver {
  private client: Redis;
  
  constructor(options: RedisOptions) {
    this.client = new Redis(options);
  }
  
  async get<T>(key: string): Promise<T | null> {
    const value = await this.client.get(key);
    return value ? JSON.parse(value) : null;
  }
  
  async set<T>(key: string, value: T, ttl?: number): Promise<void> {
    const serialized = JSON.stringify(value);
    if (ttl) {
      await this.client.setex(key, ttl, serialized);
    } else {
      await this.client.set(key, serialized);
    }
  }
  
  async delete(key: string): Promise<boolean> {
    const result = await this.client.del(key);
    return result > 0;
  }
  
  async deletePattern(pattern: string): Promise<number> {
    const keys = await this.client.keys(pattern);
    if (keys.length === 0) return 0;
    return this.client.del(...keys);
  }
  
  async clear(): Promise<void> {
    await this.client.flushdb();
  }
}

// Use it
const cache = new Cache({
  driver: new RedisDriver({ host: 'localhost', port: 6379 })
});

Requirements

  • Node.js >= 18.0.0

Documentation

For full documentation, visit docs.teliagen.org.

License

Apache-2.0