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

cache-tree

v0.5.0

Published

A class for storing client-side data for reuse with an LRU algorithm.

Downloads

19

Readme

cachetree.js

CacheTree is a class for storing client-side data objects in a nested object structure. Data can be easily retrieved by passing an object as a filter into one of its methods. CacheTree can also give an approximation of data missing using a diff method to reduce the amount of data needed to be fetched. CacheTree also implements a Least Recently Used cache replacement algorithm to limit the amount of memory used by the cache.

Use

Create a new cacheTree with the new operator. The constructor takes two arguments: hierarchy[array], maxSize[number][optional]. The first argument is an array of strings. The order of the array determines the hierarchy of the tree, the first element being the top level, and the last element being at the bottom. A second optional argument is a number (positive integer) that gives the maximum number of objects to be stored in the cache before evicting data.

const cache = new CacheTree(['level_1', 'level_2', ..., 'level_n']);

Tests

There are tests for each method in the API. Please see the tests for descriptions and expected behavior.

LRU algorithm

CacheTree implements a Least Recently Used cache replacement algorithm. As data is added to the cache, a linked list keeps the order of new data and recently accessed data. New and recently used data is placed in the front of the list, while unused cached data works its way towards the end of the list. When the cache reaches it's maxSize, old data is removed from the list and cache.

API

Method | Arguments | Return | Description --- | :---: | :---: | --- get | filter[object] | array | Returns an array of data stored in the cache that satisfies the filter. Each data object is a new object. set | data[object or array] | none | Inserts a data object or an array of data objects into the cache. The data is nested into the cache object by its keys and hierarchy provided in the constructor. clone | none | object | Creates a new CacheTree object with the same cache object and linked list. has | filter[object] | boolean | Returns false if cache is missing any part of the cartesian product of the parameters provided in the filter. Returns true otherwise. getDiff | paramFilter[object] | object | Returns an object similar to paramFilter. The returned object describes the smallest cartesian product of parameters needed to fill in missing data for paramFilter. clearCache | none | none | Replaces the cache with an empty object and creates a new linked list. getSize | none | number | Returns the number of data objects stored in the cache. extract | filter[object] | array | Like get, but removes returned data from cache.