1.0.2 • Published 6 years ago

kasza-js v1.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

Kasza.js

Kasza.js is simple Cache service/helper/tool for your App.

Getting Started

Prerequisites

This package is using UMD pattern, so it means that you can use it:

  • in Node.js project
  • browser running project
    • without AMD
    • with AMD

Installation

Option A: With npm

npm install kasza-js

Option B: Download

Download version that fits your better:

Compressed version - 1.44KB

Uncompressed version - 2.41KB

And simply add HTML tag:

<script type="text/javascript" src="kasza.min.js"></script>

Usage

Basic set and get

// set value 'kiszony' for id 'ogorek'
Kasza.set('ogorek', 'kiszony');

// get value for id 'ogorek'
Kasza.get('ogorek'); // will return 'kiszony'

What's special about it? Well, you can use it as storage between files. Example:

In file1.js:

import Kasza

var commonData = {
  key: value,
  fn: function() {
    return true;
  }
};

Kasza.set('common data', commonData);

In file2.js:

import Kasza

var commonData = Kasza.get('commmon data');

Use TTL (Time To Live)

In file1.js:

import Kasza

var temporaryData = [1, 2, 3];

// set TTL to 1 minute (60,000ms)
Kasza.set('tmp data', temporaryData, 60000);

In file2.js:

import Kasza

var temporaryData = Kasza.get('tmp data'); // will return proper data

setTimeout(function() {
  temporaryData = Kasza.get('tmp data'); // will return undefined
}, 60001);

Use Debug

Enable/Disable Debug
Kasza.setup({
  // by default it's false
  debug: true
});
Use custom debug function
Kasza.setup({
  debug: function(msg) {
    // do something with msg
  }
})

TODO

  • save Cache in IndexedDB (if user wishes to)

FAQ

  • Why "Kasza"? What does it mean? How should I even pronounce it?!

    Kasza is Polish word and means groats, kasha. According to Wiktionary it's pronounced /ˈka.ʂa/.

    Why? Well - because for kasza for me sounds simmilar to cache. That's all 😊

Authors

  • Marek Sierociński - Initial work - marverix

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details