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

flk-number-counter

v1.0.6

Published

Animated number counter for Falak framework

Downloads

2

Readme

Cache

The cache system is built on LocaleStorage API.

Installation

flk install flk-cache

OR

npm install flk-cache

Alias: cache.

Table of contents

Usage

Once you resolve the cache object you can use the methods below.


class HomePage {
    /**
     * {@inheritDoc}
     */
    constructor(cache) {
        this.cache = cache;
    } 
}

Available methods

Set

set(key: String, value: any, expiresAt: Number = Cache.FOREVER): Self

This method accepts any type of values, the cache engine will handle it automatically, so if you want to store object, you don't have to JSON.stringify it, the package will take care of it.

The expiresAt parameter is used to determine until when the value should be stored in.

Please note that this method accepts a valid timestamp number, i.e Date.now().

The default value for expiresAt is set to Cache.FOREVER which mean the value will not be removed from the cache until the user clears the browser history.

There are some useful constants for cache expiration time.

Examples

let cache = DI.resolve('cache');

cache.set('name', 'Hasan');

// It can also store objects
let user = {
    name: 'Hasan',
    address: 'Some street address',
};

cache.set('user', user);

// storing arrays is acceptable as well
let users = [{
    name: 'Hasan',
    address: 'Some street address',
}, {
    name: 'John Doe',
    address: 'Another address',
}];

cache.set('users', users);

// cache for one hour
cache.set('accessToken', MyAccessToken, Cache.FOR_ONE_HOUR);11

Get

get(key: String, defaultValue: any = null): any|null

Retrieve value from cache.

If the key doesn't exist, defaultValue will be returned instead.

Examples

let cache = DI.resolve('cache');

// if the given key exists
let name = cache.get('name'); // Hasan

// if the given key doesn't exists, return null
let age = cache.get('age'); // null

// if the given key doesn't exists, return the given default value instead.
let email = cache.get('email', '[email protected]'); // [email protected]

Has

has(key: String): Boolean

Determine if the given key exists in cache.

Examples

let cache = DI.resolve('cache');

if (cache.has('name')) {
    // do something
}

Remove

remove(key: String): void

Remove the given key if exists in cache storage.

Examples

let cache = DI.resolve('cache');

cache.remove('name');

Clear

clear(): void

Clear all cache values.

Examples

let cache = DI.resolve('cache');

cache.clear();

Configurations

Available configurations for cache in Application configurations.

Main Configuration key: cache

| key | Type | Default value | Description | | ------------- | --------- | ------------- | -------------------------------------------------------------------------------------- | | encryptValues | Boolean | true | If set to true, any value will be encrypted using the Crypto package. |

It's recommended to set the type of the encryptionValue in your config.js in the beginning of your application development as it works on all the cached values.

Constants

| constant | Description | | --------------------- | ------------------------------------------------------------- | | Cache.FOR_ONE_HOUR | Cache the value for one hour. | | Cache.FOR_TWO_HOURS | Cache the value for two hours. | | Cache.FOR_ONE_DAY | Cache the value for one day. | | Cache.FOR_ONE_WEEK | Cache the value for one week. | | Cache.FOR_ONE_MONTH | Cache the value for one month. | | Cache.FOR_ONE_YEAR | Cache the value for one year. | | Cache.FOREVER | Cache the value until the visitor clears the browser history. |