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

@themost/cache

v2.9.0

Published

MOST web Framework Caching Module

Downloads

79

Readme

@themost/cache

MOST Web Framework Data Caching

@themost/cache implements the default data caching strategy that is going to be used by any @themost data application

Important note: This module has been separated from @themost/data even if it exports the default caching strategy.

Installation

npm i @themost/cache

Configuration

@themost/cache/platform-server#DefaultDataCachingStrategy is being registered by @themost/data#DataConfiguration:

{
    "services": [
        {
            "serviceType": "@themost/cache#DataCacheStrategy",
            "strategyType": "@themost/cache/platform-server#DefaultDataCacheStrategy"
        }
    ]
}
    

Configure absolute expiration timeout by setting absoluteExpiration under settings/cache section:

{
    "settings": {
        "cache": {
            "absoluteExpiration": 900
        }
    }
}

This setting is going to be used by node-cache which is the caching engine initiated by @themost/cache#DefaultDataCacheStrategy strategy.

@themost/cache/platform-server#IndexedCacheStrategy is an alternative caching strategy which uses disk for caching items.

{
    "services": [
        {
            "serviceType": "@themost/cache#DataCacheStrategy",
            "strategyType": "@themost/cache/platform-server#IndexedCacheStrategy"
        }
    ]
}

Configure disk cache root under settings/cache section (the default value is .cache/diskCache):

{
    "settings": {
        "cache": {
            "absoluteExpiration": 900,
            "rootDir": ".cache/diskCache"
        }
    }
}

and the interval -in seconds- of validating the expiration of cached items:

{
    "settings": {
        "cache": {
            "absoluteExpiration": 900,
            "rootDir": ".cache/diskCache",
            "checkingPeriod": 60
        }
    }
}

Checkout other data caching strategies like @themost/memcached, @themost/redis etc.

Output caching

@themost/cache#OutputCaching enables caching mechanisms on expressjs application based on pre-defined cache profiles

e.g.

const clientCacheProfile = {
    location: 'client',
    duration: 60 * 60, // 1 hour
    varyByHeader: [
        'accept',
        'accept-encoding',
        'accept-language',
        'accept-profile'
    ],
    varyByParam: [
        '*' // use any query param
    ],
    varyByCallback: async (req) => {
        if (req.headers.authorization) {
            return `context=${MD5(req.headers.authorization).toString()}`
        }
        return null;
    } 
}

...

// setup cache
app.use(OutputCaching.setup({
    rootDir: '.cache/indexedCache',
    absoluteExpiration: 20 * 60 // 20 minutes,
    checkingPeriod: 60 * 1000 // 1 minute
}));

...

app.use('/api/hello', OutputCaching.cache(clientCacheProfile), (req, res, next) => {
    return res.json({
        message: 'Hello World'
    });
});

where /api/hello response will be cached on client side based on several parameters defined in clientCacheProfile.

OutputCaching.cache(PreOutputCacheConfiguration)

Caches response based on cache profile parameters

duration

int

Gets or sets the time duration in seconds during which the response is cached.

location

string

Gets or sets the output cache location.

| | | |---|---| | client | The output cache is located on the browser | server | The output cache is located on the server | serverAndClient | The output cache is located both on the client and server | none | The output cache is disabled | any | The output cache is located both on the client and server

varyByHeader

string[]

Gets or sets an array of headers used to vary the cached output

varyByParam

string[]

Gets or sets an array of query string params used to vary the cached output

varyByContentEncoding

string

Gets or sets a content encoding which will be used to vary the cached output

varyByCallback

function(): Promise<string>

varyByCallback() method may used to programmatically vary the cached output.