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

goobs-cache

v1.7.2

Published

A versatile caching and state management solution for JavaScript applications. Offers serverless, session, and cookie-based caching with support for encryption, compression, and auto-optimization. Provides a Jotai-like API for seamless integration. Handle

Downloads

274

Readme

goobs-cache

A versatile and efficient caching and state management solution for TypeScript and JavaScript applications. goobs-cache features multiple storage options, encryption, compression, and flexible data management across different environments.

Features

  • Multiple storage options:
    • Serverless caching with LRU strategy
    • Client-side storage (cookies and session storage)
  • Two-layer caching: Automatically syncs between serverless and client-side storage for optimal performance and offline capabilities.
  • Cross-environment support: Works seamlessly in both client-side and server-side environments.
  • Unified state management: Provides functionality similar to React's useContext and useState.
  • Enhanced security: Implements AES-GCM encryption for data protection.
  • Optimized storage: Utilizes compression to reduce storage footprint.
  • TypeScript support: Offers strong typing for improved developer experience.

Installation

npm install goobs-cache

Or using yarn:

yarn add goobs-cache

Basic Usage

Here's a simple example of how to use goobs-cache:

import { serverless, session, cookie, twoLayer } from 'goobs-cache';

// Two-layer caching (automatically syncs between serverless and client-side)
await twoLayer.update('userProfile', 'userStore', { name: 'Alice', age: 28 });
const userProfile = await twoLayer.get('userProfile', 'userStore');
console.log(userProfile); // { name: 'Alice', age: 28 }

// Serverless caching
const serverlessAtom = serverless.atom('serverData', 'dataStore');
await serverlessAtom.set('Hello, Serverless!');
const serverValue = await serverlessAtom.get();
console.log(serverValue); // 'Hello, Serverless!'

// Client-side caching (session storage)
const sessionAtom = session.atom('Hello, Session!');
const [sessionValue, setSessionValue] = session.useAtom(sessionAtom);
console.log(sessionValue); // 'Hello, Session!'
setSessionValue('Updated Session Value');

// Client-side caching (cookies)
const cookieAtom = cookie.atom('cookieData', 'cookieStore');
await cookieAtom.set('Hello, Cookies!');
const cookieValue = await cookieAtom.get();
console.log(cookieValue); // 'Hello, Cookies!'

// Removal
await twoLayer.remove('userProfile', 'userStore');
await serverlessAtom.remove();
await cookieAtom.remove();

// Clearing all caches
await twoLayer.clear();
await serverless.clear();
await cookie.clear();

// Updating configuration
twoLayer.updateConfig();
serverless.updateConfig();
session.updateConfig();
cookie.updateConfig();

Advanced Features

goobs-cache offers advanced capabilities for complex use cases:

  • Two-layer caching: Automatically synchronizes data between serverless and client-side storage, providing seamless offline capabilities and improved performance.
  • Automatic client-side caching: When using the serverless mode on the client-side, data is automatically cached in session storage for faster subsequent access.
  • Flexible storage options: Choose between twoLayer, serverless, session, and cookie modes to best suit your application's needs.

Configuration

Configure goobs-cache using a .cache.config.ts file in your project's root. Here's a comprehensive example:

import { CacheConfig, EvictionPolicy, LogLevel } from 'goobs-cache';

const cacheConfiguration: CacheConfig = {
  serverless: {
    cacheSize: 10000,
    cacheMaxAge: 86400000,
    persistenceInterval: 600000,
    maxMemoryUsage: 1073741824,
    evictionPolicy: 'lru' as EvictionPolicy,
    prefetchThreshold: 0.9,
    forceReset: false,
    compression: {
      compressionLevel: -1,
    },
    encryption: {
      algorithm: 'aes-256-gcm',
      encryptionPassword: 'your-secure-encryption-password-here-serverless',
      keyCheckIntervalMs: 86400000,
      keyRotationIntervalMs: 7776000000,
    },
  },
  session: {
    cacheSize: 5000,
    cacheMaxAge: 1800000,
    evictionPolicy: 'lru' as EvictionPolicy,
    compression: {
      compressionLevel: -1,
    },
    encryption: {
      algorithm: 'aes-256-gcm',
      encryptionPassword: 'your-secure-encryption-password-here-session',
      keyCheckIntervalMs: 86400000,
      keyRotationIntervalMs: 7776000000,
    },
  },
  cookie: {
    cacheSize: 1000,
    cacheMaxAge: 604800000,
    maxCookieSize: 4096,
    evictionPolicy: 'lru' as EvictionPolicy,
    compression: {
      compressionLevel: -1,
    },
    encryption: {
      algorithm: 'aes-256-gcm',
      encryptionPassword: 'your-secure-encryption-password-here-cookie',
      keyCheckIntervalMs: 86400000,
      keyRotationIntervalMs: 7776000000,
    },
  },
  global: {
    keySize: 256,
    batchSize: 100,
    autoTuneInterval: 3600000,
    loggingEnabled: true,
    logLevel: 'debug' as LogLevel,
    logDirectory: 'logs',
  },
};

export default cacheConfiguration;

TypeScript Support

goobs-cache is written in TypeScript and provides comprehensive type definitions for a great developer experience.

Performance

goobs-cache is designed for high performance, with features like:

  • Two-layer caching for optimal data access
  • LRU caching strategy
  • Compression to reduce data size

Security

Security is a top priority in goobs-cache:

  • AES-GCM encryption for data at rest
  • Secure key management with regular key rotation
  • Client-side encryption in browsers

License

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

Author

goobs-cache is developed and maintained by Matthew Goluba.

Contact

For questions or feedback:

Elevate your data management strategy with goobs-cache!