stash-it is a caching mechanism based on plugins.
It's core concept is to stay simple, small and easily extendable using plugins.
Plugins allow you to:
- write handlers for hook'able methods
- extend API of cache object
stash-it can be used in various environments (client, server or native), depending on what adapter you use.
It's very small ~2kB (including memory adapter, minified + gzipped) with no dependencies whatsoever.
At one time, I was looking for a cache mechanism for node, that would allow me to add tags to stored items. I found some solutions. But when I dug deeper I started to find various modules that were either too big, had too few / many methods, were hard to use or not maintained for a very long time.
Then I thought - if there isn't anything close to what I am looking for, why not create something of my own.
That's how stash-it came to be.
npm install stash-it --save
stash-it is just a core module, which provides means to create cache or register plugins. It doesn't come with any adapter or plugin out of the box. Therefore you will either need to provide an adapter or install one:
npm install stash-it-adapter-memory --save
Now, you have everything for the most basic usage of stash-it.
Let's give it a try
(mind that I am using ES6 syntax)
;;// First, we need to create an adapterconst adapter = ;// Now, let's create cache instanceconst cache = ;// Cool! Now time for some actionscache;cache; // trueconst item = cache;console; // some very often fetched value I need to storecache; // truecache; // false
And that's pretty much it.
stash-it is build in ES6 for modern environments. If you need to run it in older ones,
you will have to transpile it. See
.babelrc file for more details.
(for v2 head over here.)
- Dawid Młynarz for creating stash-it's logo;