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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@cachehub/core

v1.0.2

Published

## Overview The core package of the caching library provides the foundational interfaces and factory pattern for creating cache implementations. It defines the contracts that all cache adapters must adhere to, ensuring a consistent API for interacting wit

Readme

Core Cache Library

Overview

The core package of the caching library provides the foundational interfaces and factory pattern for creating cache implementations. It defines the contracts that all cache adapters must adhere to, ensuring a consistent API for interacting with different caching strategies.

Benefits

  • Unified Interface: All cache implementations conform to the same interface, making it easy to switch between them.
  • Factory Pattern: The factory pattern allows for dynamic creation of cache instances based on configuration.

Interfaces

CacheInterface

The CacheInterface defines the methods that all cache implementations must implement:

  • set(key: string, value: TypeValue, expiresAfter?: number): Promise<boolean>
  • get(key: string): Promise<TypeValue | undefined>
  • delete(key: string): Promise<boolean>
  • has(key: string): Promise<boolean>

CacheFactoryInterface

The CacheFactoryInterface defines the method for creating cache instances:

  • createCache(config: TypeConfig): Promise<CacheInterface>

Usage

To use the core functionalities, follow these steps:

  1. Import the necessary interfaces and factory from the core package.
  2. Implement your custom cache adapter by extending the CacheInterface.
  3. Create a factory class that implements the CacheFactoryInterface.

Example

import { CacheInterface, CacheFactoryInterface } from '@cachehub/core';

class MyCustomCache implements CacheInterface {
  // Implement the required methods: set, get, delete, has
}

class MyCustomCacheFactory implements CacheFactoryInterface {
  public async createCache(config: any): Promise<CacheInterface> {
    return new MyCustomCache();
  }
}

To make your package self-registering, ensure your package registers the factory with the CacheFactoryRegistry and exports the factory class as the default export in index.ts. For example:

import { CacheFactoryRegistry } from '@cachehub/core';
import { MyCustomCacheFactory } from './Factory';

CacheFactoryRegistry.registerCacheFactory('my-custom-cache', MyCustomCacheFactory);

// default export so that core factory can use it directly
export default MyCustomCacheFactory;

Generic Type Usage

The CacheInterface supports generic types for type-safe storage and retrieval of values. Here are examples of how to use generics with the cache methods:

// Using primitive types
await cache.set<string>('stringKey', 'value');
const stringValue = await cache.get<string>('stringKey');

await cache.set<number>('numberKey', 42);
const numberValue = await cache.get<number>('numberKey');

await cache.set<boolean>('booleanKey', true);
const booleanValue = await cache.get<boolean>('booleanKey');

// Using complex objects
interface User {
  id: number;
  name: string;
  email: string;
}

const user: User = {
  id: 1,
  name: 'John Doe',
  email: '[email protected]'
};

await cache.set<User>('userKey', user);
const userValue = await cache.get<User>('userKey');

// Using arrays
await cache.set<string[]>('arrayKey', ['a', 'b', 'c']);
const arrayValue = await cache.get<string[]>('arrayKey');

When implementing a custom cache adapter, make sure to properly handle the generic types in your implementation to maintain type safety throughout the application.

Folder Structure

The folder structure for each package typically includes:

  • src/: Contains the source code for the package, including:
    • Factory/: Contains factory classes for creating cache handler.
    • Cache/: Contains classes that implement the cache object.
    • Type/: Contains type definitions and interfaces.
  • tests/: Contains unit tests for the package.
  • README.md: Documentation for the package.
  • .env: Environment variables for configuration.

Contributing

Contributions are welcome! Feel free to fork this repository and submit pull requests. Before submitting, please ensure your code passes all linting and unit tests.

You can format code using:

pnpm format

You can run unit tests using:

pnpm test