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

@ndcode/text_cache

v0.1.0

Published

Load text files which can be changed while system is live

Downloads

6

Readme

Build Cache wrapper for text files

An NDCODE project.

Overview

The text_cache package exports a single constructor TextCache(diag) which must be called with the new operator. The resulting cache object stores the utf-8-decoded text of text files loaded from disk.

See the build_cache package for more information. The TextCache object is essentially a wrapper object which routes the request between the build_cache package and the asynchronous fs.readFile() API of Node.js, to ensure that the file is retrieved from either RAM or disk as required.

Calling API

Suppose one has a TextCache instance named tc. It behaves somewhat like an ES6 Map object, except that it only has the tc.get() function, because new objects are added to the cache by attempting to get them.

The interface for the TextCache-provided instance function tc.get() is:

await tc.get(key) — retrieves the object stored under key, where key is the on-disk pathname to a text file. A String is returned, as in await util.promisify(fs.readFile)(key, {encoding: 'utf-8'}), except that the pathname and the decoded result are cached for future reuse.

Before returning the cached copy, the existence and modification time of the text file on disk is checked to make sure that the cache is up-to-date. Otherwise, if the file doesn't exist an ENOENT exception is thrown, or if the file exists it is loaded and decoded and the cache updated for next time.

About diagnostics

The diag argument to the constructor is a bool, which if true causes messages to be printed via console.log() for all activities except for the common case of retrieval when the object is already up-to-date. A diag value of undefined is treated as false, thus it can be omitted in the usual case.

To be implemented

It is intended that we will shortly add a timer function (or possibly just a function that the user should call periodically) to flush built templates from the cache after a stale time. There is otherwise no way to delete an object from the cache, except by first deleting it on disk, then trying to get it.

GIT repository

The development version can be cloned, downloaded, or browsed with gitweb at: https://git.ndcode.org/public/text_cache.git

License

All of our NPM packages are MIT licensed, please see LICENSE in the repository.

Contributions

The caching system is under active development (and is part of a larger project that is also under development) and thus the API is tentative. Please go ahead and incorporate the system into your project, or try out our example webserver built on the system, subject to the caution that the API could change. Please send us your experience and feedback, and let us know of improvements you make.

Contact: Nick Downing [email protected]