Delete Only On Update?

33 views
Skip to first unread message

Justin Noel

unread,
Jan 25, 2014, 8:33:42 AM1/25/14
to angula...@googlegroups.com
In http://jmdobry.github.io/angular-cache/configuration.html#onexpire under "Another Example", the docs show using `newCache.get` with a callback function.  This callback would be called if the cache is expired.  However, this does not work.  Instead, I get this error :

Error: AngularCache.get(key, options): options: must be an object!
at j.get (http://localhost:8000/js/lib/angular-cache-2.2.0.min.js:10:9935)

I believe that this means, it should have been passed an object like " { onExpire : function( key, value) { ...  })"

However, I can't get that to work either.

Can you help with an explanation of how to get this to work?

Thanks,
Justin Noel

Justin Noel

unread,
Jan 25, 2014, 8:38:15 AM1/25/14
to angula...@googlegroups.com
For example, I have tried this:

    var invitationsCache = $angularCacheFactory('invitationsCache', {
        maxAge          : 1000,           // Items added to this cache expire after 5 minutes.
        recycleFreq     : 20000,            // Check for expiry every 20 seconds
        deleteOnExpire  : 'passive',       // Items will be deleted from this cache right when they expire.
        storageMode     : 'localStorage',
        verifyIntegrity : true
    });


        var isGoodThisYear = true;
        var value = invitationsCache.get('invitations',
            { onExpire : function (key, value) {

                console.log('It has expired!');
                if (isGoodThisYear) {

                    console.log('Just putting them back');
                    invitationsCache.put(key, value);

                } else {

                    console.log('Going to get new');
                    $http.get(invitations).success(function (data) {
                        invitationsCache.put(key, data);
                    });

                }
            }
        });
 


However, the onExpire never gets called.

Justin Noel

unread,
Jan 25, 2014, 9:27:32 AM1/25/14
to angula...@googlegroups.com
I've worked out my problem from the example below.  However, the documentation still needs to be fixed.  It needs to show that the callback is an Object, not just a function.



On Saturday, January 25, 2014 7:33:42 AM UTC-6, Justin Noel wrote:

Jason Dobry

unread,
Jan 25, 2014, 12:42:56 PM1/25/14
to angula...@googlegroups.com
Sorry about the documentation being out of date. It previously was just a function, but now an object. I'll get the documentation fixed. Thanks.

Jason Dobry

unread,
Jan 25, 2014, 1:17:49 PM1/25/14
to angula...@googlegroups.com
The documentation should be clearer now.

Justin Noel

unread,
Jan 25, 2014, 5:01:05 PM1/25/14
to angula...@googlegroups.com
I don't really see any change to the documentation.  It still just shows the second argument to newCache.get being a function:




On Saturday, January 25, 2014 7:33:42 AM UTC-6, Justin Noel wrote:
Reply all
Reply to author
Forward
0 new messages