Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@hapi/catbox-memory

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hapi/catbox-memory

Memory adapter for catbox

  • 4.1.1
  • unpublished
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
855K
increased by2.78%
Maintainers
1
Weekly downloads
 
Created

What is @hapi/catbox-memory?

@hapi/catbox-memory is a memory-based caching module for the hapi.js framework. It provides a simple and efficient way to store and retrieve data in memory, making it useful for scenarios where quick access to cached data is required.

What are @hapi/catbox-memory's main functionalities?

Basic Caching

This code demonstrates how to set up a basic in-memory cache using @hapi/catbox-memory. It initializes a Catbox client with the memory engine, sets a value in the cache, and retrieves it.

const Catbox = require('@hapi/catbox');
const CatboxMemory = require('@hapi/catbox-memory');

const client = new Catbox.Client(CatboxMemory);

const start = async () => {
  await client.start();
  const key = { id: 'example', segment: 'examples' };
  await client.set(key, 'my cached value', 10000); // Cache for 10 seconds
  const cached = await client.get(key);
  console.log(cached.item); // Outputs: 'my cached value'
};

start();

Cache Expiration

This code demonstrates how to set a cache expiration time. The cached value will expire after 5 seconds, and attempting to retrieve it after 6 seconds will return null.

const Catbox = require('@hapi/catbox');
const CatboxMemory = require('@hapi/catbox-memory');

const client = new Catbox.Client(CatboxMemory);

const start = async () => {
  await client.start();
  const key = { id: 'example', segment: 'examples' };
  await client.set(key, 'my cached value', 5000); // Cache for 5 seconds
  setTimeout(async () => {
    const cached = await client.get(key);
    console.log(cached); // Outputs: null (cache expired)
  }, 6000);
};

start();

Cache Deletion

This code demonstrates how to delete a cache entry. After setting a value in the cache, it is deleted using the drop method, and subsequent retrieval returns null.

const Catbox = require('@hapi/catbox');
const CatboxMemory = require('@hapi/catbox-memory');

const client = new Catbox.Client(CatboxMemory);

const start = async () => {
  await client.start();
  const key = { id: 'example', segment: 'examples' };
  await client.set(key, 'my cached value', 10000); // Cache for 10 seconds
  await client.drop(key); // Delete the cache entry
  const cached = await client.get(key);
  console.log(cached); // Outputs: null (cache deleted)
};

start();

Other packages similar to @hapi/catbox-memory

Keywords

FAQs

Package last updated on 14 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc