Changelog

Last updated 4 months ago

Changes since v2.0

registerPlugins

There are three changes:

  1. registerPlugins was imported from stash-it; now it is internally built into cacheInstance.

  2. This method now takes one parameter: array of plugins.

  3. Returned cacheInstance is freezed (using Object.freeze), so that returned object is immutable.

Before:

import { registerPlugins } from 'stash-it';
const cacheWithPlugins = registerPlugins(cache, [ plugin ]);

Now:

const cacheWithPlugins = cache.registerPlugins([ plugin ]);

It felt more naturally that given cache instance should be able to register plugins on itself.

This method still returns newly created cache instance. Therefore:

cacheWithPlugins === cache; // false

getExtensions -> createExtensions

getExtensions was renamed to createExtensions. It also takes an object as an argument. That object is passed (by plugins):

  • cacheInstance

  • getPreData

  • getPostData

Before:

import { getPreData, getPostData } from 'stash-it';
// plugin's body
{
getExtensions: (cacheInstnace) => {
...
}
}

Now:

// plugin's body
{
createExtensions: ({ cacheInstance, getPreData, getPostData }) => {
...
}
}

That happened because testing plugins against getPreData and getPostData was hard. Now, that they're passed as dependencies, it is trivial to stub them.

key validation

Key validation happened in adapters (basic one). Now it is moved to stash-it, and is even simpler - checks if key is a string, throws otherwise. If any storage needs to validate this string further, given adapter should do it.

bugfix with hooks

In stash-it v2, hooks are passed by reference, therefore registering more plugins (with hooks, one by one, not few at a time), registers them on all cache instances. Since v3 this is fixed and each plugin registering (that returns a new cache instance) sets hooks only on the newly returned instance.

ES6

stash-it is still written in ES6, but also stays that way. It is about using the code that current environments use (be it node or browsers). Should you need ES5 code - you need to transpile it yourself.