JSPM

stash-it-plugin-readonly

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q16346F
  • License MIT

Read only plugin for stash-it

Package Exports

  • stash-it-plugin-readonly

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (stash-it-plugin-readonly) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

logo-stash-it-color-dark 2x

stash-it-plugin-readOnly

build status Coverage Status

Read-only plugin for stash-it.

The problem

Let's say you need to have an instance of stash-it that is only capable of reading from the storage, but not writing, changing or deleting anything.

Solution

This plugin will allow you to do just that. And if anyone will try to write / delete something, an error will be thrown.

Installation

npm i stash-it-plugin-readonly --save

Usage

import { createCache } from 'stash-it';
import createReadOnlyPlugin from 'stash-it-plugin-readonly';

// You can use any adapter
import createMemoryAdapter from 'stash-it-adapter-memory';

const cacheInstance = createCache(createMemoryAdapter());

const readOnlyPlugin = createReadOnlyPlugin();
const readOnlyCacheInstance = cacheInstance.registerPlugins([ readOnlyPlugin ]);

// This will work
readOnlyCacheInstance.hasItem('key');

// But this will throw
readOnlyCacheInstance.removeItem('key');

// or this
readOnlyCacheInstance.setItem('key', 'value');

Methods that will throw are: setItem, addExtra, setExtra and removeItem. All other will work just fine.

Demo

Edit x5p5op0j4