Coder Social home page Coder Social logo

active-cache's Introduction

ActiveCache Build Status

A simple caching object with TTL

Table of Contents

Installation

<script src="/path/to/active-cache.js"></script>

Download the latest standalone JavaScript files (ES5)

Usage

Syntax

new ActiveCache(options?)
  • options (optional)
    • Type: Object
    • The options for the caching. Check out the available options.

Example

const activeCache = new ActiveCache({prefix: 'c', stTTL: null});
activeCache.set("myKey", "A value", 60);

// After 40 minutes:
activeCache.get("myKey")
//=> {value: "myKey", ttl: 1575952773409}

// After 1 hour:
activeCache.get("myKey")
//=> null

Options

The ActiveCache class also support multiple optional configurations. These should be passed as an object to the ActiveCache class object. If no manual configurations are set, default options are used.

stTTL

  • Type: Boolean
  • Default: null

Standard time to live. null = unlimited time.

prefix

  • Type: String
  • Default: c

The prefix is used for all keys in the stored in SessionStorage, on the form prefix:key.

Methods

set(key, value, ttl?)

  • key:

    • Type: String
    • Key for storing the value.
  • value:

    • Type:
    • Any value that can be converted to JSON.
  • ttl:

    • Type: Number or null
    • "Time to live", the time a cache object is valid. null = unlimited time.
  • (return value):

    • Type: Boolean
    • Returns true if the entry was successfully stored. False otherwise.

Sets a key value pair.

get(key)

  • key:

    • Type: String
    • Key for storing the value.
  • (return value):

    • Type: Object
    • Returns the item stored by the provided key.

Gets an item on the form {value: "value", ttl: 1575952773409}, stored by a given key.

del(key)

  • key:

    • Type: String
    • Key for the entry to be deleted.
  • (return value):

    • Type: Object
    • Returns the item stored by the provided key.

Deletes an entry with the given key.

clear()

Deletes all entries stored by the ActiveCache with the currently used prefix.

Build instructions

Clone a copy of the main active-cache git repo by running:

git clone git://github.com/andstor/active-cache.git

Enter the active-cache directory and run the build script:

npm run build

active-cache's People

Contributors

andstor avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.