Code Monkey home page Code Monkey logo

cachefactory's Introduction

CacheFactory Bower NPM Tests Downloads Coverage

CacheFactory is a very simple and useful synchronous key-value store for the browser.

Table of Contents

Installation

NPM

npm install --save cachefactory

Bower

bower install --save cachefactory

Quick Start

import { CacheFactory } from 'cachefactory';

const cacheFactory = new CacheFactory();
let cache;

// Check whether cache metadata has been initialized
// on every page refresh.
if (!cacheFactory.exists('my-cache')) {
  // Create the cache metadata. Any previously saved
  // data will be loaded.
  cache = cacheFactory.createCache('my-cache', {
    // Delete items from the cache when they expire
    deleteOnExpire: 'aggressive',

    // Check for expired items every 60 seconds
    recycleFreq: 60 * 1000
  });
}

cache.put('/books/1', { title: 'BookOne', id: 1 });

Documentation

License

MIT License

Copyright (C) 2015-2017 CacheFactory project authors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

cachefactory's People

Contributors

alan-agius4 avatar asarzina avatar delagen avatar greenkeeperio-bot avatar jmdobry avatar jutaz avatar samuelmarks avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cachefactory's Issues

How to use typings?

import CacheFactory = require("cachefactory");
const base: CacheFactory.Cache = new CacheFactory().createCache("cache", {});

TS2503:Cannot find namespace 'CacheFactory'.

Does CacheFactory Supports Angular 1?

Does CacheFactory supports AngularJS application as well? I am using both AngularJS and Angular2+ in my project. Does this library will give leverage so that if I load data in cache by angular 2, will it be able to use it in angular 1 also?

Performance issue in IE when getting/putting many objects

We notice a big hit on performance in IE 11 when we need to get/put ~1000 objects to the cache in a loop. After some analysis, it looks like the serialization process and the lruHeap are causing the slowness. We are using mem cache and are not using the LRU policy, can the serialization process and the lruHeap be disabled/bypass when they are not needed to be used?

onExpire does not return the value of the cached item if storage is not in memory

The following returns the value of the cached item only if it is present in the expiresHeap:

{
    key: 'removeExpired',
    value: function removeExpired() {
      // ...
      while ((expiredItem = this.$$expiresHeap.peek()) && expiredItem.expires <= now) { 
        expired[expiredItem.key] = expiredItem.value ? expiredItem.value : null;
        this.$$expiresHeap.pop();
      }

      // ...

      if (this.$$onExpire) {
        Object.keys(expired).forEach(function (key) {
          _this6.$$onExpire(key, expired[key]);
        });
      }
      // ...
    }
}

However, the heap will only contain the value if you're using in-memory storage:

{
    key: 'put',
    value: function put(key, value) {
      // ...

      if (this.$$storage) {
        // ...
        this.$$expiresHeap.push({
          key: key,
          expires: item.expires
        });
      } else {
        // ...
        
        this.$$expiresHeap.push(item);
        // ...
      }
     // ...
    }
}

Ideally, it should work regardless of what storage option you use e.g. local storage.

Accept more than number as maxAge (and others)

http://www.w3.org/TR/2011/WD-html5-20110525/timers.html#timers

When the above methods are to get the timeout, they must run the following steps:

  1. Let timeout be the second argument to the method, or zero if the argument was omitted.
  2. Apply the ToString() abstract operation to timeout, and let timeout be the result. [ECMA262]
    3. Apply the ToNumber() abstract operation to timeout, and let timeout be the result. [ECMA262]
  3. If timeout is an Infinity value, a Not-a-Number (NaN) value, or negative, let timeout be zero.
  4. Round timeout down to the nearest integer, and let timeout be the result.
  5. Return timeout.

So:

http://www.ecma-international.org/ecma-262/6.0/index.html#sec-tonumber
calls http://www.ecma-international.org/ecma-262/6.0/index.html#sec-toprimitive
which calls valueOf

Effectively: each data structure, primitive or object that abstract operation ToNumber can cast to a number should be a valid value of all options that now require number

Real life example: http://momentjs.com/docs/#/durations/
Duration implements valueOf and it returns duration length as milliseconds.
CacheFactory triggers an error where it shouldn't when duration is passed - browser can handle that.

TypeError: CacheFactory.createCache is not a function && angular 2 integration problem "task is undefined"

Hello. I've got this error on https://github.com/jmdobry/CacheFactory/tree/master/build_examples

stan@rapture:~/Dev/CacheFactory/build_examples/browserify$ npm -v
3.7.3
stan@rapture:~/Dev/CacheFactory/build_examples/browserify$ node -v
v5.8.0

What I'm doing wrong?

var CacheFactory2 = require('../../');
var CacheFactory = require('./cachefactory.min.js');
var CacheFactory3 = require('./cachefactory.js');

console.log(CacheFactory2);
console.log(CacheFactory);
console.log(CacheFactory3);


var testCache2 = CacheFactory.createCache('test');
console.log(testCache2);
var testCache = CacheFactory3.createCache('test');



Object { entry: "./app.js", output: Object, resolve: Object } bundle.js:52:2
function c() bundle.js:53:2
Object { entry: "./app.js", output: Object, resolve: Object } bundle.js:54:2
Object { $$id: "test", destroy: a/$[e].destroy(), disable: a/$[e].disable(), enable: a/$[e].enable(), get: a/$[e].get(), info: a/$[e].info(), keys: a/$[e].keys(), keySet: a/$[e].keySet(), put: a/$[e].put(), remove: a/$[e].remove(), 24 more… } bundle.js:58:2

TypeError: CacheFactory3.createCache is not a function

But when i'm import min version all works fine.

I'm also have trouble with integration with angular 2

EXCEPTION: Error during instantiation of AppComponent!. angular2.js:23730:9

ORIGINAL EXCEPTION: TypeError: task is undefined angular2.js:23730:9

ORIGINAL STACKTRACE: angular2.js:23730:9

patchTimer/clearNative</<@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:142:10
clearInterval@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575 line 953 > Function:1:40
a/$[e].setRecycleFreq@http://localhost:8080/my-app/app/components/cachefactory.js:1:9453
a/$[e].setOptions@http://localhost:8080/my-app/app/components/cachefactory.js:1:8475
a@http://localhost:8080/my-app/app/components/cachefactory.js:1:11587
AppComponent@http://localhost:8080/my-app/app/components/app.component.js:22:25
ReflectionCapabilities</ReflectionCapabilities.prototype.factory/<@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:1519:20
Injector</Injector.prototype._instantiate@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:11127:19
Injector</Injector.prototype._instantiateProvider@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:11069:16
Injector</Injector.prototype._new@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:11059:14
InjectorInlineStrategy</InjectorInlineStrategy.prototype.instantiateProvider@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:10823:14
ElementDirectiveInlineStrategy</ElementDirectiveInlineStrategy.prototype.init@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:8923:18
AppElement@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:8613:9
viewFactory_HostAppComponent0@viewFactory_HostAppComponent:71:31
AppViewManager_</AppViewManager_.prototype.createRootHostView@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:6701:18
DynamicComponentLoader_</DynamicComponentLoader_.prototype.loadAsRoot/<@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:12388:27
Zone</ZoneDelegate</ZoneDelegate.prototype.invoke@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:322:20
NgZoneImpl/this.inner<.onInvoke@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:2216:22
Zone</ZoneDelegate</ZoneDelegate.prototype.invoke@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:321:20
Zone</Zone</Zone.prototype.run@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:218:25
scheduleResolveOrReject/<@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:567:53
Zone</ZoneDelegate</ZoneDelegate.prototype.invokeTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:355:24
NgZoneImpl/this.inner<.onInvokeTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:2208:22
Zone</ZoneDelegate</ZoneDelegate.prototype.invokeTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:354:24
Zone</Zone</Zone.prototype.runTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:254:29
drainMicroTaskQueue@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:473:26
ZoneTask/this.invoke@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:425:22
 angular2.js:23730:9

ERROR CONTEXT: angular2.js:23730:9

Object { element: <sd-app>, componentElement: null, injector: Object } angular2.js:23730:9

EXCEPTION: Error: Uncaught (in promise): EXCEPTION: Error during instantiation of AppComponent!.
ORIGINAL EXCEPTION: TypeError: task is undefined
ORIGINAL STACKTRACE:
patchTimer/clearNative</<@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:142:10
clearInterval@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575 line 953 > Function:1:40
a/$[e].setRecycleFreq@http://localhost:8080/my-app/app/components/cachefactory.js:1:9453
a/$[e].setOptions@http://localhost:8080/my-app/app/components/cachefactory.js:1:8475
a@http://localhost:8080/my-app/app/components/cachefactory.js:1:11587
AppComponent@http://localhost:8080/my-app/app/components/app.component.js:22:25
ReflectionCapabilities</ReflectionCapabilities.prototype.factory/<@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:1519:20
Injector</Injector.prototype._instantiate@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:11127:19
Injector</Injector.prototype._instantiateProvider@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:11069:16
Injector</Injector.prototype._new@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:11059:14
InjectorInlineStrategy</InjectorInlineStrategy.prototype.instantiateProvider@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:10823:14
ElementDirectiveInlineStrategy</ElementDirectiveInlineStrategy.prototype.init@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:8923:18
AppElement@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:8613:9
viewFactory_HostAppComponent0@viewFactory_HostAppComponent:71:31
AppViewManager_</AppViewManager_.prototype.createRootHostView@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:6701:18
DynamicComponentLoader_</DynamicComponentLoader_.prototype.loadAsRoot/<@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:12388:27
Zone</ZoneDelegate</ZoneDelegate.prototype.invoke@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:322:20
NgZoneImpl/this.inner<.onInvoke@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:2216:22
Zone</ZoneDelegate</ZoneDelegate.prototype.invoke@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:321:20
Zone</Zone</Zone.prototype.run@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:218:25
scheduleResolveOrReject/<@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:567:53
Zone</ZoneDelegate</ZoneDelegate.prototype.invokeTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:355:24
NgZoneImpl/this.inner<.onInvokeTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:2208:22
Zone</ZoneDelegate</ZoneDelegate.prototype.invokeTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:354:24
Zone</Zone</Zone.prototype.runTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:254:29
drainMicroTaskQueue@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:473:26
ZoneTask/this.invoke@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:425:22

ERROR CONTEXT:
[object Object] angular2.js:23740
EXCEPTION: Error: Uncaught (in promise): EXCEPTION: Error during instantiation of AppComponent!.
ORIGINAL EXCEPTION: TypeError: task is undefined
ORIGINAL STACKTRACE:
patchTimer/clearNative</<@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:142:10
clearInterval@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575 line 953 > Function:1:40
a/$[e].setRecycleFreq@http://localhost:8080/my-app/app/components/cachefactory.js:1:9453
a/$[e].setOptions@http://localhost:8080/my-app/app/components/cachefactory.js:1:8475
a@http://localhost:8080/my-app/app/components/cachefactory.js:1:11587
AppComponent@http://localhost:8080/my-app/app/components/app.component.js:22:25
ReflectionCapabilities</ReflectionCapabilities.prototype.factory/<@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:1519:20
Injector</Injector.prototype._instantiate@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:11127:19
Injector</Injector.prototype._instantiateProvider@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:11069:16
Injector</Injector.prototype._new@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:11059:14
InjectorInlineStrategy</InjectorInlineStrategy.prototype.instantiateProvider@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:10823:14
ElementDirectiveInlineStrategy</ElementDirectiveInlineStrategy.prototype.init@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:8923:18
AppElement@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:8613:9
viewFactory_HostAppComponent0@viewFactory_HostAppComponent:71:31
AppViewManager_</AppViewManager_.prototype.createRootHostView@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:6701:18
DynamicComponentLoader_</DynamicComponentLoader_.prototype.loadAsRoot/<@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:12388:27
Zone</ZoneDelegate</ZoneDelegate.prototype.invoke@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:322:20
NgZoneImpl/this.inner<.onInvoke@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:2216:22
Zone</ZoneDelegate</ZoneDelegate.prototype.invoke@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:321:20
Zone</Zone</Zone.prototype.run@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:218:25
scheduleResolveOrReject/<@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:567:53
Zone</ZoneDelegate</ZoneDelegate.prototype.invokeTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:355:24
NgZoneImpl/this.inner<.onInvokeTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:2208:22
Zone</ZoneDelegate</ZoneDelegate.prototype.invokeTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:354:24
Zone</Zone</Zone.prototype.runTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:254:29
drainMicroTaskQueue@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:473:26
ZoneTask/this.invoke@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:425:22

ERROR CONTEXT:
[object Object] angular2.js:23730:9

STACKTRACE: angular2.js:23730:9

resolvePromise@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:534:32
scheduleResolveOrReject/<@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:570:18
Zone</ZoneDelegate</ZoneDelegate.prototype.invokeTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:355:24
NgZoneImpl/this.inner<.onInvokeTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:2208:22
Zone</ZoneDelegate</ZoneDelegate.prototype.invokeTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:354:24
Zone</Zone</Zone.prototype.runTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:254:29
drainMicroTaskQueue@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:473:26
ZoneTask/this.invoke@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:425:22
 angular2.js:23730:9

Unhandled Promise rejection: EXCEPTION: Error during instantiation of AppComponent!.
ORIGINAL EXCEPTION: TypeError: task is undefined
ORIGINAL STACKTRACE:
patchTimer/clearNative</<@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:142:10
clearInterval@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575 line 953 > Function:1:40
a/$[e].setRecycleFreq@http://localhost:8080/my-app/app/components/cachefactory.js:1:9453
a/$[e].setOptions@http://localhost:8080/my-app/app/components/cachefactory.js:1:8475
a@http://localhost:8080/my-app/app/components/cachefactory.js:1:11587
AppComponent@http://localhost:8080/my-app/app/components/app.component.js:22:25
ReflectionCapabilities</ReflectionCapabilities.prototype.factory/<@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:1519:20
Injector</Injector.prototype._instantiate@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:11127:19
Injector</Injector.prototype._instantiateProvider@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:11069:16
Injector</Injector.prototype._new@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:11059:14
InjectorInlineStrategy</InjectorInlineStrategy.prototype.instantiateProvider@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:10823:14
ElementDirectiveInlineStrategy</ElementDirectiveInlineStrategy.prototype.init@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:8923:18
AppElement@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:8613:9
viewFactory_HostAppComponent0@viewFactory_HostAppComponent:71:31
AppViewManager_</AppViewManager_.prototype.createRootHostView@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:6701:18
DynamicComponentLoader_</DynamicComponentLoader_.prototype.loadAsRoot/<@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:12388:27
Zone</ZoneDelegate</ZoneDelegate.prototype.invoke@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:322:20
NgZoneImpl/this.inner<.onInvoke@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:2216:22
Zone</ZoneDelegate</ZoneDelegate.prototype.invoke@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:321:20
Zone</Zone</Zone.prototype.run@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:218:25
scheduleResolveOrReject/<@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:567:53
Zone</ZoneDelegate</ZoneDelegate.prototype.invokeTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:355:24
NgZoneImpl/this.inner<.onInvokeTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:2208:22
Zone</ZoneDelegate</ZoneDelegate.prototype.invokeTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:354:24
Zone</Zone</Zone.prototype.runTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:254:29
drainMicroTaskQueue@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:473:26
ZoneTask/this.invoke@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:425:22

ERROR CONTEXT:
[object Object] ; Zone: angular ; Task: Promise.then ; Value: Object { _wrapperMessage: "DI Exception", _originalException: TypeError, _originalStack: "patchTimer/clearNative</<@http://lo…", _context: null, _wrapperStack: "WrappedException@http://localhost:8…", keys: Array[1], injectors: Array[1], stack: "" } angular2-polyfills.js:460:14

Error: Uncaught (in promise): EXCEPTION: Error during instantiation of AppComponent!.
ORIGINAL EXCEPTION: TypeError: task is undefined
ORIGINAL STACKTRACE:
patchTimer/clearNative</<@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:142:10
clearInterval@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575 line 953 > Function:1:40
a/$[e].setRecycleFreq@http://localhost:8080/my-app/app/components/cachefactory.js:1:9453
a/$[e].setOptions@http://localhost:8080/my-app/app/components/cachefactory.js:1:8475
a@http://localhost:8080/my-app/app/components/cachefactory.js:1:11587
AppComponent@http://localhost:8080/my-app/app/components/app.component.js:22:25
ReflectionCapabilities</ReflectionCapabilities.prototype.factory/<@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:1519:20
Injector</Injector.prototype._instantiate@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:11127:19
Injector</Injector.prototype._instantiateProvider@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:11069:16
Injector</Injector.prototype._new@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:11059:14
InjectorInlineStrategy</InjectorInlineStrategy.prototype.instantiateProvider@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:10823:14
ElementDirectiveInlineStrategy</ElementDirectiveInlineStrategy.prototype.init@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:8923:18
AppElement@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:8613:9
viewFactory_HostAppComponent0@viewFactory_HostAppComponent:71:31
AppViewManager_</AppViewManager_.prototype.createRootHostView@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:6701:18
DynamicComponentLoader_</DynamicComponentLoader_.prototype.loadAsRoot/<@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:12388:27
Zone</ZoneDelegate</ZoneDelegate.prototype.invoke@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:322:20
NgZoneImpl/this.inner<.onInvoke@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:2216:22
Zone</ZoneDelegate</ZoneDelegate.prototype.invoke@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:321:20
Zone</Zone</Zone.prototype.run@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:218:25
scheduleResolveOrReject/<@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:567:53
Zone</ZoneDelegate</ZoneDelegate.prototype.invokeTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:355:24
NgZoneImpl/this.inner<.onInvokeTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:2208:22
Zone</ZoneDelegate</ZoneDelegate.prototype.invokeTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:354:24
Zone</Zone</Zone.prototype.runTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:254:29
drainMicroTaskQueue@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:473:26
ZoneTask/this.invoke@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:425:22

ERROR CONTEXT:
[object Object]
Stack trace:
resolvePromise@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:534:32
scheduleResolveOrReject/<@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:570:18
Zone</ZoneDelegate</ZoneDelegate.prototype.invokeTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:355:24
NgZoneImpl/this.inner<.onInvokeTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:2208:22
Zone</ZoneDelegate</ZoneDelegate.prototype.invokeTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:354:24
Zone</Zone</Zone.prototype.runTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:254:29
drainMicroTaskQueue@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:473:26
ZoneTask/this.invoke@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:425:22
 angular2-polyfills.js:462:10

Unhandled Promise rejection: EXCEPTION: Error during instantiation of AppComponent!.
ORIGINAL EXCEPTION: TypeError: task is undefined
ORIGINAL STACKTRACE:
patchTimer/clearNative</<@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:142:10
clearInterval@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575 line 953 > Function:1:40
a/$[e].setRecycleFreq@http://localhost:8080/my-app/app/components/cachefactory.js:1:9453
a/$[e].setOptions@http://localhost:8080/my-app/app/components/cachefactory.js:1:8475
a@http://localhost:8080/my-app/app/components/cachefactory.js:1:11587
AppComponent@http://localhost:8080/my-app/app/components/app.component.js:22:25
ReflectionCapabilities</ReflectionCapabilities.prototype.factory/<@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:1519:20
Injector</Injector.prototype._instantiate@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:11127:19
Injector</Injector.prototype._instantiateProvider@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:11069:16
Injector</Injector.prototype._new@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:11059:14
InjectorInlineStrategy</InjectorInlineStrategy.prototype.instantiateProvider@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:10823:14
ElementDirectiveInlineStrategy</ElementDirectiveInlineStrategy.prototype.init@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:8923:18
AppElement@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:8613:9
viewFactory_HostAppComponent0@viewFactory_HostAppComponent:71:31
AppViewManager_</AppViewManager_.prototype.createRootHostView@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:6701:18
DynamicComponentLoader_</DynamicComponentLoader_.prototype.loadAsRoot/<@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:12388:27
Zone</ZoneDelegate</ZoneDelegate.prototype.invoke@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:322:20
NgZoneImpl/this.inner<.onInvoke@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:2216:22
Zone</ZoneDelegate</ZoneDelegate.prototype.invoke@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:321:20
Zone</Zone</Zone.prototype.run@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:218:25
scheduleResolveOrReject/<@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:567:53
Zone</ZoneDelegate</ZoneDelegate.prototype.invokeTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:355:24
NgZoneImpl/this.inner<.onInvokeTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:2208:22
Zone</ZoneDelegate</ZoneDelegate.prototype.invokeTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:354:24
Zone</Zone</Zone.prototype.runTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:254:29
drainMicroTaskQueue@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:473:26
ZoneTask/this.invoke@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:425:22

ERROR CONTEXT:
[object Object] ; Zone: <root> ; Task: Promise.then ; Value: Object { _wrapperMessage: "DI Exception", _originalException: TypeError, _originalStack: "patchTimer/clearNative</<@http://lo…", _context: null, _wrapperStack: "WrappedException@http://localhost:8…", keys: Array[1], injectors: Array[1], stack: "" } angular2-polyfills.js:460:14

Error: Uncaught (in promise): EXCEPTION: Error during instantiation of AppComponent!.
ORIGINAL EXCEPTION: TypeError: task is undefined
ORIGINAL STACKTRACE:
patchTimer/clearNative</<@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:142:10
clearInterval@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575 line 953 > Function:1:40
a/$[e].setRecycleFreq@http://localhost:8080/my-app/app/components/cachefactory.js:1:9453
a/$[e].setOptions@http://localhost:8080/my-app/app/components/cachefactory.js:1:8475
a@http://localhost:8080/my-app/app/components/cachefactory.js:1:11587
AppComponent@http://localhost:8080/my-app/app/components/app.component.js:22:25
ReflectionCapabilities</ReflectionCapabilities.prototype.factory/<@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:1519:20
Injector</Injector.prototype._instantiate@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:11127:19
Injector</Injector.prototype._instantiateProvider@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:11069:16
Injector</Injector.prototype._new@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:11059:14
InjectorInlineStrategy</InjectorInlineStrategy.prototype.instantiateProvider@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:10823:14
ElementDirectiveInlineStrategy</ElementDirectiveInlineStrategy.prototype.init@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:8923:18
AppElement@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:8613:9
viewFactory_HostAppComponent0@viewFactory_HostAppComponent:71:31
AppViewManager_</AppViewManager_.prototype.createRootHostView@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:6701:18
DynamicComponentLoader_</DynamicComponentLoader_.prototype.loadAsRoot/<@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:12388:27
Zone</ZoneDelegate</ZoneDelegate.prototype.invoke@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:322:20
NgZoneImpl/this.inner<.onInvoke@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:2216:22
Zone</ZoneDelegate</ZoneDelegate.prototype.invoke@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:321:20
Zone</Zone</Zone.prototype.run@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:218:25
scheduleResolveOrReject/<@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:567:53
Zone</ZoneDelegate</ZoneDelegate.prototype.invokeTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:355:24
NgZoneImpl/this.inner<.onInvokeTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2.js?1458383153576:2208:22
Zone</ZoneDelegate</ZoneDelegate.prototype.invokeTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:354:24
Zone</Zone</Zone.prototype.runTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:254:29
drainMicroTaskQueue@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:473:26
ZoneTask/this.invoke@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:425:22

ERROR CONTEXT:
[object Object]
Stack trace:
resolvePromise@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:534:32
resolvePromise@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:519:18
scheduleResolveOrReject/<@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:567:18
Zone</ZoneDelegate</ZoneDelegate.prototype.invokeTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:355:24
Zone</Zone</Zone.prototype.runTask@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:254:29
drainMicroTaskQueue@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:473:26
ZoneTask/this.invoke@http://localhost:8080/my-app/node_modules/angular2/bundles/angular2-polyfills.js?1458383153575:425:22
 angular2-polyfills.js:462:10

I'm not sure maybe it's related because only way to import cachefactory is

var CacheFactory = require('./cachefactory.js');
import {CacheFactory} from 'cachefactory';

return undefined

Allow async implementation of cache interface

I tried to connect angular-cache with ocombe/angular-localForage (in general - CacheFactory and mozilla/localForage) but it turns out that async storge implementation is not supported by CacheFactory. For example index.js#L417-L420:

$$storage().removeItem(this.$$prefix + '.data.' + key);
var keysJson = $$storage().getItem(this.$$prefix + '.keys');
var keys = keysJson ? utils.fromJson(keysJson) : [];
var index = keys.indexOf(key);

this clearly does not allow removeItem and getItem to return promises.

@jmdobry are you interested in implementing async storage in CacheFactory? Do you see any obvious cons for this idea?

touch doesn't honor key-specific options

I hoped to leverage CacheFactory's maxAge to expire items at different intervals. (e.g. session data expires at 12h, but an authentication is locally expunged at 5 minutes idle).

      var options = {
        deleteOnExpire: 'aggressive',
        cacheFlushInterval: CACHE_DURATION,
        storageMode: 'localStorage',
        onExpire: function(){$log.warn("local session expiring"); logout();} 
      };
      CacheFactory.createCache(SESSION_CACHE, options);
CacheFactory.get(SESSION_CACHE).put(CURRENT_USER_KEY,
              username.toUpperCase(),
              {maxAge: AUTH_DURATION});

I expected that CacheFactory.get(SESSION_CACHE).touch(CURRENT_USER_KEY); options specified on the initial PUT would be preserved.

kwv@ef28025 adds options object to the API, however I wasn't certain of the usecase behind https://github.com/jmdobry/CacheFactory/blob/master/src/index.js#L819

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.