A plugin is an object that consists of, at least, one property: hooks
and / or createExtensions
. Here is an example of full grown plugin (without the body):
{hooks: [],createExtensions: ({ cacheInstance, getPreData, getPostData }) => {}}
If you take for example stash-it-plugin-debug you gain two things (read more on this plugin's repo page):
Data that flows in, through and out of each cache's method is going to be tracked (using passed callback, e.g. console.log
).
Adds new method runDiangnostics()
.
Here's how you use it:
import createDebugPlugin from 'stash-it-plugin-debug';// assuming that you already have cache instanceconst debugPlugin = createDebugPlugin(console.log);const cacheWithPlugins = cache.registerPlugins([ debugPlugin ]);// without the plugin, this method would not be herecacheWithPlugins.runDiagnostics(); // runs the diagnosticscache.runDiagnostics(); // error, runDiagnostics is not a function