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

ssm-cfg-manager

v2.0.0

Published

Simple caching tool for SSM parameters

Downloads

975

Readme

ssm-cfg-manager

npm version contributions welcome Known Vulnerabilities dependencies

Simple library to store SSM parameters in memory with multi-region, automatic renewal, expiration and parsing support.

@aws-sdk/client-ssm is a peer dependency, make sure that you provide it yourself if needed

:warning: aws-sdk v2 is no longer supported upward of ssm-cfg-manager Version 2.0.0

Documentation

Use it wisely! :tada:

Get an instance of SSMHandler

To get an instance of a SSMHandler which is a singleton with caching build in. You need to call the getInstance method on the StaticSSMHandler class.

This will return a singleton instance of SSMHandler with caching. So for each region you can create an instance and caching will be bound to it. For when you have the same keys stored in multiple regions.

const ssmHandler: SSMHandler = StaticSSMHandler.getInstance(region: string = "eu-west-1");

Get uncached data using getUnCachedText or getUnCachedJSon

When you want to retrieve data from SSM but not cache the value use the unCached methods.

// return a JSON object of generic type T
const parsed: T = await this.getUnCachedJson<T>(key);

// returns a string
const text: string = await this.getUnCachedText(key);

Get cached data using getText and getJson

When you want to cache data you can use the getText and getJson method from the SSMHandler instance.

Cache for limited time

If you specify a timeout, the library will expire the cached entry. When an entry has expired, the library will attempt to fetch it again from the AWS Parameter Store.

This is done on demand and not proactively.

// return a JSON object of generic type T and cache it for 5 seconds
const parsed: T = await ssmHandler.getJson<T>(key, 5000);

// returns a string and cache it for 5 seconds
const text: string = await ssmHandler.getText(key, 5000);

When you cached something ones with a timer, there is no need to specify it in other calls.

// cache it for 5 seconds
const parsed: T = await ssmHandler.getJson<T>(key, 5000);

// cache it for 5 seconds as it remembers the time from the first call
const text: string = await ssmHandler.getText(key);

Cache without expiration

If you specify no timeout the object will never expire and live in memory until the application stops or you remove the entry manually from the cache.

// return a JSON object of generic type T and cache it permanently
const parsed: T = await ssmHandler.getJson<T>(key);

// returns a string and cache it permanently
const text: string = await ssmHandler.getText(key);

Clearing the cache

When you need to wipe the cash for some reason you can use the clearCache method on the SSMHandler or the flush method on the CacheHandler.

ssmHandler.clearCache();

// or

ssmHandler.cacheHandler.flush();

Acting on the cache

To interact with the cache, use the CacheHandler instance from the SSMHandler. This however isn't necessary for using the library.

/* 
 * Safely checks if an key exists in cache.
 * this will remove the object if it has expired/
 */
ssmHandler.cacheHandler.has(key: string): boolean;

/* 
 * Check if a key exists without removing it when it expired.
 */
ssmHandler.cacheHandler.hasUnsafe(key: string): boolean;

/*
 * Put an item in the cache for the given time or no time at all
 * when a time has been set before it will remember it based on the key.
 */
public put<T>(key: string, value: T, cacheForMs?: number): void;

/*
 * Remove the given item from the cache
 */
public remove(key: string): void

/*
 * Gets an obejct from the cache
 * Will throw NotFoundError when the object does not exist on cache
 * Will throw ExpiredError when the object exists but has been expired
 */
public get<T>(key: string): CachedObject<T>

Contributing

Feel free to open a PR, writing unit tests is required. If you have any questions or issues feel free to open up an issue and I will get back to you asap.

This project is not prone to change as it's just a simple implementation to make using SSM parameters a bit easier.

If it does change, SemVer applies.