npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jimcares

v1.0.6

Published

JavaScript In-Memory CAching, REsource Singleton

Downloads

5

Readme

Jimcares

JavaScript In-Memory CAching REsource Singleton

npm Build Status npm bundle size npm GitHub last commit GitHub issues

Jimcares is a singleton for JavaScript in-memory caching. It is used to store complex data in memory, or large api responses which only need fetching once. It allows for querying the properties within large data structures, as well as more simple read/write functionality.

Note: Currently, the only driver shipped with Jimcares uses the window object. It is therefore at this stage a browser plugin only, and will not currently work with Node.

Usage

Unpkg

<script src="https://unpkg.com/jimcares/dist/jimcares.min.js"></script>

Npm

npm install jimcares

Yarn

yarn add jimcares

You can require the Jim singleton like so:

const Jim = require('jimcares');

Alternatively, you can import the module directly if you are using an ES6-aware build tool like Webpack or Rollup, which makes use of the 'module' field in package.json.

import Jim from 'jimcares';

API

Jim.init()

Initialise Jim. The default expiration will be 24 hours if this property is not specified. Setting a custom queryNotation will allow you to query nested objects. The default is a slash. See Querying Objects for more information.
Parameter {object} options
Returns void
Throws TypeError

let options = {
	defaultExpiration: "4 hours",
	queryNotation: "."
}
Jim.init(options);

Jim.remember()

Tell Jim to remember a value. You can override the default expiration for a given root.
Parameter {string} path
Parameter {mixed} value
Parameter {string} expiration
Returns boolean
Throws TypeError

Jim.remember('example', {example: true}, '10 minutes');

Jim.has()

Check if Jim has a value at the given path.
Parameter {string} path
Returns boolean
Throws TypeError

Jim.has('example') === true;

Jim.get()

Get the value at the given path.
Parameter {string} path
Returns mixed
Throws TypeError

Jim.get('example');

Jim.root()

Get the root at the given path, including: value, created_at, updated_at, deleted_at, expires_at.
Parameter {string} path
Returns object
Throws TypeError

Jim.root('example');

Jim.trash()

Soft-delete the root at the given path. This sets the deleted_at property to the value of a current timestamp.
Parameter {string} path
Returns void
Throws TypeError

Jim.trash('example');

Jim.isTrashed()

Check if the root at the given path has been soft-deleted. Note: this method will return false if the path is undefined.
Parameter {string} path
Returns boolean
Throws TypeError

Jim.isTrashed('example') === true;

Jim.forget()

Forget the root at the given path permanently.
Parameter {string} path
Returns void
Throws TypeError

Jim.forget('example');

Jim.flush()

Flush the cache of all its roots.
Returns void

Jim.flush();

Jim.equals()

Check if a given value of a path matches the given comparison.
Parameter {string} path
Parameter {mixed} comparison
Returns boolean
Throws TypeError

Jim.equals('example', 'Does not match') === false;

Jim.writeToLS()

Writes the entire cache to local storage. This can be used for later retrieval.
Returns void
Throws Error if the client does not support local storage

Jim.writeToLS();

Jim.toJson()

Get the entire cache as a JSON string.
Returns string

Jim.toJson();

Jim.destroy()

Removes __jimcares from the window entirely. Note: The Jim singleton will still be present, so you can run the init() method again at any time.
Returns void

Jim.destroy();

In Progress

Note: the below methods are currently available but are being refactored into a stats method, and will soon be deprecated.

Get an approximate size of the entire cache in bytes.
Jim.size()

Count the number of roots in the cache.
Jim.count()

Querying objects

Jim.get() and Jim.has() both support the querying of objects. You can use certain notations to get nested properties or check they exist. For example:

let data = {
	"foo": {
		"bar": "val" 
	}
};

Jim.remember('example', data);
Jim.get('example/foo/bar') === "val"
Jim.has('example/foo/bar') === true

Note: slash notation is the default. You can specify an alternative via the init method.