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

backbone-fetch-cache-indexeddb

v5.0.2

Published

Caching for Backbone's fetch method using IndexedDB

Downloads

20

Readme

backbone-fetch-cache-indexeddb

This is a plugin for Backbone.js. It also works with Backbone-based frameworks like Marionette.

It overwrites the fetch Method of Backbone.Model and Backbone.Collection and cachees all fetched data in the browsers IndexedDB.

This can reduces unesseccary API calls significantly!

Status

NPM

Build Status Dependency Status devDependency Status

GitHub issues Percentage of issues still open Average time to resolve an issue

Installation

npm install --save backbone-fetch-cache-indexeddb

Initialization

Just insert the script after Backbone.

<script src="backbone.min.js"></script>
<script src="dist/backbone.fetch-cache.indexeddb.min.js"></script>

First the IndexedDb needs to be initialized. This is only neccessare once e.g. after loading your Application:

Backbone.fetchcache.init({
	name: "MyApplicationCache",
	enabled: false,
	maxAge: Infinity
})

Options

name

REQUIRED

The Name of your IndexedDB Store. This should be unique to your application.

enabled

OPTIONAL

Enable the cache by default for all requests. This can be overwritten by setting cache:false or cache:true on the inidividual fetch call. [Default: false]

maxAge

OPTIONAL

Default max age in seconds. This can be overwritten by setting maxAge on the inidividual fetch call. [Default: Infinity]

Usage

MockyModel = Backbone.Model.extend({
  url: 'http://www.mocky.io/v2/5185415ba171ea3a00704eed'
});

var model = new MockyModel();

// 1. download data from server
model.fetch({
  // Cache this request.
  cache: true
});

// 2. request the data again: it is loaded instantly from cache.
model.fetch({
  // Check is the data is availible in the cache.
  cache: true,
  // Cache expires in seconds. Here one hour.
  maxAge: 60*60
})

// 3. force a refresh from server
model.fetch({
  // Enable chaching for this request
  cache: true,
  // force a refresh from server
  maxAge: -1
})

Events

Backbone.fetchcache extends Backbone.Events and provides the following events. These events are mainly for logging or debugging puropses:

  • getitem: An item was read from the cache. Callback parameters: key, data, maxAge.
  • setitem: An item was saved to the cache. Callback parameters: key, data.
  • aged: An item was found but is is too old to be valid. Callback parameters: key, data, maxAge.
  • notfound: This is event is fired, when the requested item does not exist in the cache. Callback parameters: key.
  • clear: The cache was cleared. Callback parameters: none.

In addition to the original events (e.g. sync, error ...) the following events get triggered at the model or collection:

  • cacherequest: Like the original request event this is fired, when a request (getItem) to the cache has started. This is usefull e.g. to show a loading-view.

Development

You should never manually change files in the dist folder. They are generated.

After changing the sources in the src folder you can run npm run test to build an test your cahnges.

During development you can start the tests in your local browser with npm run watch. This will also watch for changes in the tests or the sources.

References

License

Licensed under the MIT license 2017 by Alexander Wunschik and contributors.