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

factomd-cache

v0.2.2

Published

A caching layer for the Factom API. Improves the performance of querying over and searching through chains on the Factom API using a hybrid memory+disk cache.

Downloads

15

Readme

factomd-cache

A caching layer for the Factom API. Improves the performance of querying over and searching through chains on the Factom API using a hybrid memory+disk cache.

The cache polls for new pending entries and stores them in the cache (every 10 seconds by default).

Compatible with Factom.js by Paul Bernier for you other NodeJS heads!

Installing

Command Line

npm i factomd-cache

package.json

"dependencies": {
	"factomd-cache": "^0.2.0"
}

Examples

Initialization

const {FactomdCache} = require('factomd-cache');

//default settings: FactomdAPI on localhost:8088, localhost wallet on port 8089
var factomdCache = new FactomdCache();

//alternate configuration options
var factomdCache = new FactomdCache({
    factomdParams:{ //see https://www.npmjs.com/package/factom#instantiate-factomcli
		factomd: {
            host: 'localhost',
            port: 8088
		}
    }  	
});

Cache a Chain

Before anything meaningful can be done, the chain must be retrieved from Factom and stored! You can call cacheChain in advance when you know a chain your application will need to access often.

Calling other functions before calling cacheChain will cause an implicit call to cacheChain before the desired function's callback completes.

After a chain is cached, new and currently pending entries will be synced on a 10 second basis.

//Testnet test Chain ID:
const testChainID = 'f1be007d4b82e7093f2234efd1beb429bc5e0311e9ae98dcd580616a2046a6b3';

//use async/await
let entries = await factomdCache.cacheChain(testChainID);

//or promises
let entries = factomdCache.cacheChain(testChainID)
.then(function(entries){
    console.log('chain is cached!');
}).catch(function(err){throw err});

Get All Entries For a Chain

let entries = await factomdCache.getAllChainEntries(testChainID);

Get The Latest Entries For a Chain

//get the most recent 25 entries for the test chain
 let entries = await factomdCache.getLatestChainEntries(testChainID);

//specify count
let entries = await factomdCache.getLatestChainEntries(testChainID, 20);

Get Entries For a Chain By Index Range

You can get entries by chronological index!

//get entries from index range 5 (inclusive) to 10(exclusive)
let entries = await factomdCache.getRangedChainEntries(testChainID, 5, 10);

Listen For New Entries

You can listen for new entries by chain as they're committed to Factom. The chain must be in the cache to receive events

factomdCache.on('new-entries', testChainID, function (newEntries) {
        console.log('Got ' + newEntries.length + ' new entries in listnener for chain '+testChainID);
});

Clear A Chain From The Cache

Clear a single chain from the cache by ID. This will stop any pending entry listeners for your chain and clear the memory+disk cache.

factomdCache.clearChain(testChainID);

Close The Cache

Stops all event listeners

factomdCache.close();

Testing

Command Line

npm test