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

@astro-my/cache

v1.0.5

Published

Cache wrapper to use ioredis conviently"

Downloads

1

Readme

Astro Cache Service (Redis)

This service reads from env variables to connect from redis store. This service supports cluster and simple redis setup.

ENV VARIABLES

cacheHost // required, default to 127.0.0.1,

cachePort // required, default to 6379

cacheCluster // optional, 1 - true, 0 - false

cachePassword // optional

For cluster, give the multiple host comma seperated.

Or you can provide these, configuration in configure function

This library will first check env variables, then user provided configuration. If both not found it will use default values

Cache Usage

const cache = require('@astro-my/cache');

cache.configure();

OR
-----

cache.configure({
  cacheHost: '127.0.0.1',
  cachePort: 6379
});

cache.run();

Retrieving Items From The Cache

The get method on the Cache is used to retrieve items from the cache.

const value = async cache.get('key');

Checking For Item Existence

The has method may be used to determine if an item exists in the cache. This method will return false if the value is null or false:

const exists = async cache.has('key');

Retrieve & Store

Sometimes you may wish to retrieve an item from the cache, but also store a default value if the requested item doesn't exist. For example, you may wish to retrieve all users from the cache or, if they don't exist, retrieve them from the database and add them to the cache.

const exists = async cache.remember('key', seconds, () => { return Users.fetch(); });

If the item does not exist in the cache, the Closure passed to the remember method will be executed and its result will be placed in the cache with ttl of seconds passed as second argument.

Retrieve & Delete

If you need to retrieve an item from the cache and then delete the item, you may use the pop method. Like the get method, null will be returned if the item does not exist in the cache:

const value = async cache.pop('key');

Retrive fields associated with particular key

Returns the values associated with the specified fields in the hash stored at key.

const values = async cache.multiget('key', [...fieldKey (String)]);

Storing data in cache

You may use the put method to store items in the cache. When you place an item in the cache, you need to specify the number of seconds for which the value should be cached: P.S: all expiry values are in seconds. If not provided, the key will be stored permenantely

const stored = async cache.put('key', value, expiry);

The method will return true if the item is stored to the cache

Store If Not Present

The put method will only add the item to the cache if it does not already exist in the cache store. The method will return true if the item is actually added to the cache. Otherwise, the method will return false:

const stored = async cache.put('key', value, expiry);

Store Set under particular key

Sets the specified fields to their respective values in the hash stored at key. This command overwrites any specified fields already existing in the hash. If key does not exist, a new key holding a hash is created.

cache.multiset('key', { field1: 'value1', field2: 'value2' }, expiry);

Removing Items From The Cache

You may remove items from the cache using the destroy method:

cache.destroy('key');