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

@fwieland/attic

v1.0.8

Published

Sophisticated caching

Downloads

4

Readme

attic

Attic synchronizes persistent storage such as localStorage with an object in memory to reduce access time. In addition, it can track the lifetime of an element and discard it if it is too old. To minimize null values, you must specify a fallback (for example, an API query) each time you read from the cache. If an element does not exist or the lifetime of an element has expired, the fallback function is used and the result of this function is stored with the ID passed in the Get function. This means that the cache does not have to be filled explicitly via a set function (although the possibility exists in Attic).

Installation

// with npm
npm install @fwieland/attic

// with yarn
yarn add @fwieland/attic

Usage

Here is a quick example to get you started:

import Attic from '@fwieland/attic';

const cache = new Attic("storageName", {
	lifetime: 10000, //10sec
})

cache.get("id1")
	.fallback(() => fetch('https://jsonplaceholder.typicode.com/todos/1').then(r => r.json())
	.then(content => console.log(content));

To reduce the boilerplate of extracting the json (in case of API-Requests) attic allows to specify a fallbackExtractor function.

const cache = new Attic("storageName", {
	fallbackExtractor: (r) => r.json(),
})

cache.get("id1")
	.fallback(() => fetch('https://jsonplaceholder.typicode.com/todos/1'))
	.then(content => console.log(content));

Options

You can provide different options to customize and extend attic: The provided examples are the default values of attic.

const cache = new Attic("storageName", {

	// spezifies the liftime of a item
	liftime: null,

	// will get called on the fallback promise
	fallbackExtractor: (e) => e, 

	// On default attic will load the spezific item into memory if it is the first time requested.
	// If synOnInit is true attic will load all items that are stored in the persitentCache into the memoryCache.
	syncOnInit: false, 

	// memoryCache, TS-Interface: ICache
	memoryCache: new MemoryCache(),	

	//localStorage, TS-Interface: ICache
	persistentCache: new PersistentCache(), 
})