Git Product home page Git Product logo

angular-promise-cache's People

Contributors

allantokuda avatar chrisronline avatar rictorres 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  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  avatar

angular-promise-cache's Issues

Do not cache when rejected

If request fail, library cache fail callback.
Is any possible way to not cache callback from failed request?

We can add expireOnFailure, but I don't want to remove previous cached data.

does not support IE8

In the current implementation, the hasOwnProperty is used. Do you see any other way of doing this as to still support IE8?

remove by key mask

one thing that probably should be good to add is ability to remove from cache by key mask like

return promiseCache({
                promise: function () {...                },
                key: "srv.getBy:" + args.toString(),
});

....
promiseCache.removeByMask(REGEX);

A bit more options - local storage and delaying next request

Hi,

Loving this module, saved me a lot of work.
I was thinking if you would care to improve it with a bit more options that would be extremely helpful.

  1. Local Storage
    It would be awesome if you can have a parameter "localStorage:true" that saves the latest cache and then looks it up on next run.
  2. Delaying next request (best name I could come up with...)
    What I mean by this is that when ttl is up, you wouldn't just delete the cache and make another request but actually keep the cache to have some swift display and then re-write it once promise is done.

For example, I am in process of writing app that loads all items from API once you open it, then you click for item detail and after reading it go back to the list. Your module works perfect not to do make excessive calls, but once the ttl is up and I go back to list, it is empty and I have to wait a second to fill up again. That's why I think it would be cool to still display the "old" data and refresh them once the new request is done. Just to assure that the list is never empty.

The local storage is basically for the same reason and mainly because I am wrapping my app in phonegap and publishing it on devices. Local storage would be helpful for offline access and, again, non-empty screens on re-opening the app.

I dont have really much time to spare so Im asking if you would be up for it, otherwise Im gonna go for it once I have more time and create pull request after.

Thanks and keep up great work :D

Promise function is called only once regardless of its arguments

My problem is when I call function wrapped in promiseCache with different arguments I expect it to be executed once for every unique argument. I'm not if it is a bug or I don't use it incorrectly

Here's example: http://jsfiddle.net/apuchkov/7kcs10ef/

var myApp = angular.module('myApp', ['angular-promise-cache']);

myApp
    .factory('myAwesomeModel', function ($http, promiseCache) {
        return {
            getData: function (id) {
                return promiseCache({
                    args: [id],
                    promise: function (id) {
                        $('#log').append('<p>Making HTTP call for id: ' + id + '</p>')
                        return $http.get('/echo/json/');
                    }
                });
            }
        };
    })
    .controller('myAwesomeCtrl', function ($scope, myAwesomeModel) {
        myAwesomeModel.getData(1);
        myAwesomeModel.getData(1);
        myAwesomeModel.getData(2); // I expect a second http call here
        myAwesomeModel.getData(2);
    });

Support for disabled storage

Hi,
Thanks for your work it is really usefull !

However today we noticed a problem with Chrome / Opera, in settings the user may disable the use of local data (avoid site from creating data), in the case this is totally crashing.

On line 36 :
ls = window.localStorage || {
setItem: function() { },
removeItem: function() { },
getItem: function() { }
},

The DOMException should only be caught to avoid troubles (exception is "VM1577:1 Uncaught DOMException: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.").

it's not caching data

Hi there, thanks for great plugin.

I'm using promise cache to cache 'currentuser' for instance.

First time I call it, it goes to the server, caches the promise and brings the data. The trouble is, it's going to the server each and every time I call it. It should be caching the resulting data I would've thought. What am I doing wrong?

app.factory('PromiseCacheFactory', function(Resource, promiseCache) {
return {
/* User */
getUser: function(userId) {
return promiseCache({
key: 'user_' + userId,
promise: function() {
return Resource.getUser(userId); // here goes $http call
}
});
},

A way to delete all data from chache

Hi, first of all great job and thanks for this library!

I wonder if there is a standard way to clear all keys in the cache.

This is useful when some cached data is related to one user, and if the user closes the session you may need to empty the cache instead of going one by one.

For now I just forked the repo and added a dirty hack:

    promiseCacheFunction.removeAll = function() {
      var keys = Object.keys(memos);

      for (var i = keys.length - 1; i >= 0; i--) {
        this.remove(keys[i]);
      };
    };

lodash support with local storage

It looks like the memoize function checks to see if underscore is installed and uses that. Unfortunately, lodash while faster in most other functions actually runs the promise. I was able to get around the issue by saving your default memoize function and based on an opts property I added it will revert the memoize function back to the one you have in the code. So I know that is the issue, I am just going to shut off local storage for my use case for now and if I get more time I will try and do a pull request that fixed the issue.

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.