Prefix / suffix plugin for stash-it.
Imagine there are couple of teams working on a product that uses stash-it and the same storage. Each team would like to use any keys to store the items, and not to be worried that some names are already taken.
Using this plugin, you're able to create cache instances that will make sure that all of the keys you use will have (either or both) prefix / suffix of your choosing included automatically.
npm i stash-it-plugin-prefixsuffix --save
;;// You can use any adapter;const team1Prefix = 'team1';const team2Prefix = 'team2';const cache = ;const team1PrefixPlugin = ;const team2PrefixPlugin = ;const team1CacheInstance = cache;const team2CacheInstance = cache;// TEAM 1team1CacheInstance; // falseteam1CacheInstance;const item = team1CacheInstance;itemvalue; // 11_TEAM_11itemkey; // team1key// TEAM 2team2CacheInstance; // falseteam2CacheInstance;const item = team2CacheInstance;itemvalue; // 22_TEAM_22itemkey; // team2key
Plugin extends cache instance with two methods: getPrefix() and getSuffix(). They return prefix / suffix passed upon plugin's creation.
;const prefix = 'somePrefix';const suffix = 'someSuffix';// assuming you already have cache instance createdconst plugin = ;const cacheWithPrefixSuffix = cache;cacheWithPrefixSuffix; // somePrefixcacheWithPrefixSuffix; // someSuffix
Plugin takes an object, as an argument, upon creation. This object must contain at least one of the properties: prefix and / or suffix. Can have both.
const plugin1 = ; // OKconst plugin2 = ; // OKconst plugin3 = ; // OKconst plugin4 = ; // will throw
prefix and suffix must be a string, containing any characters you want.
String(s) will be concatenated with
key like so:
But as a user, you only need to pass the
key when using stash-it's API.