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

@easy-cache/core

v0.0.1

Published

![EasyCache](https://github.com/YashKumarVerma/easy-cache/blob/master/assets/banner.png?raw=true)

Downloads

3

Readme

EasyCache

Ensure Package Builds Tests

EasyCache

A modern NodeJS package to cache any function with just a single line of code - @easy-cache

🤔 What is EasyCache v1.0?

@easy-cache is a NodeJS module available on NPM to cache any function with just a single line of code. It helps you to boost your application in the cleanest way possible. Allows setting global as well as local cache options. Supports TypeScript as well as JavaScript.

Primary features of @easy-cache are:

  • Global configuration options to configure entire application at one place.
  • Local configuration option to configure any function as required, overriding the global configs.
  • Custom TTL (Time to Live) to customize cache invalidation.
  • Built in support for Redis as cache server. (Others coming in v2.0)
  • Support for javaScript and TypeScript in a single package.
  • Single line implementation even in JS where decorators do not exist.
  • brutally tested and production ready.

Usage

The package can be directly used in any nodejs (TypeScript / JavaScript) based backend.

Step 1: Install the package

npm install @easy-cache/core

# or

yarn add @easy-cache/core

Note: In v1.0, the default cache engine i.e. redis is used, and therefore the redis package is also installed by default. From v2.0 onwards, there would be 0 dependencies in the core package.

Step 2: Initialize the cache system

/** Initializing the cache system */
import EasyCache from '@easy-cache/core'

const cacheInstance = new EasyCache({
  // TTL Value in seconds
  defaultTTL: 10,

  // redis connection details
  redisHost: '127.0.0.1',
  redisPassword: '',
  redisPort: 6379,

  // whether to show verbose logs
  debug: false,

  // completely disable the cache globally
  disable: false,
})

/** the function that you want to cache **/
function fullName(fistName, lastName) {
  return `${firstName} ${lastName}`
}

/** To cache the function, just pass it into the provider with configs..
 *
 * Configurations can be passed into the provider to change the behavior.
 * disable: to turn of cache for given funtion
 * expireAfter: to set a custom expire time for given function
 * debug: to show verbose logs for given function
 */
const cachedFullName = cacheInstance.provider({ debug: true }, fullName)

Using with classes

Since v1.0, EasyCache supports classes as well, using a unique method called decorators. Simply adding @EasyCache.Cache({configs}) will cache the following function.

Example:

class MyClass {
  @EasyCacheInstance.Cache({ defaultTTL: 30 })
  public static thisMethodWillBeCached() {
    // some code
    return true
  }
}

The above function would cache with a ttl of 30 seconds.

Tests

Tests are a vital component of any software project. In @easy-cache,

  • the unit tests are written in TypeScript using Mocha and Chai.
  • the end to end tests are being written in JavaScript using Mocha and Chai.

A detailed analysis about the above is posted here.

Roadmap

Version 1

  • @cache decorator to implement caching for class methods.
  • provider to cache orphan functions (without decorators).
  • Support for javascript and typescript.
  • Redis as a default provider for caching.
  • Robust test suite.

Version 2

  • Support for plugins to add any generic provider.
  • Support for Postgres, Memcached, etc. as providers on rolling basis.
  • Plugins