jmdobry / angular-cache Goto Github PK
View Code? Open in Web Editor NEWangular-cache is a very useful replacement for the Angular 1 $cacheFactory.
Home Page: http://jmdobry.github.io/angular-cache
License: MIT License
angular-cache is a very useful replacement for the Angular 1 $cacheFactory.
Home Page: http://jmdobry.github.io/angular-cache
License: MIT License
I just overlooked the source and wanna say thank you.
angular-cache is one of the few repos which is well documented and nice coded. I like your coding style since its going in the direction of the angular source.
Keep up the good work man!
PS: If you wanna see what else you could put in your repo, take a look at the component-seed
To see a save naming convention, checkout angular-translate
Peace!
This issue can be closed now. :)
When maxAge
is specified, the current implementation uses $timeout to actively delete items from the cache. With large caches this could tie up the cpu too much.
Lazy delete means that items aren't deleted until they are requested and have expired (no need for $timeout). This conserves cpu but uses more memory.
I'm not sure which should be the default yet.
In an app module's config()
method where service providers are configured, add the ability to configure the $angularCacheFactoryProvider
. The first configuration option that will be available will be the ability to configure global defaults for all caches produced by $angularCacheFactory
. For example: if I want all of my caches to have a capacity of 1000, I could do:
app.module('myApp', ['jmdobry.angular-cache'])
.config(function ($angularCacheFactoryProvider) {
$angularCacheFactoryProvider.setCacheDefaults({
capacity: 1000
});
})
.run(function ($angularCacheFactory) {
$angularCacheFactory('newCache').info().capacity; // 1000
});
See #36
Angular-cache needs to somehow be able to detect when another party has modified angular-cache's items that are saved in localStorage and either fix the problem or modify its own internal state to reflect the changes.
There's several places in the README where you have an example of setting the maxAge
option like this:
maxAge: 90000, // Items added to this cache expire after 15 minutes
You are missing a zero. This is actually 1.5 mins, not 15 mins. You do this in several other places with a similar claim that 600000 = 10mins.
Please tag versions so that they can be pinned. Also, it would be nice if the output filenames were not versioned (ie - angular-cache.js
/ angular-cache.min.js
rather than angular-cache-n.n.n.js
), so that references don't have to change with an update.
Return an array of the keys currently in the given cache.
Right now it returns the cache's info, which would be confusing to the developer.
The usage documentation in the readme needs to clarify that ngAdvancedCache
has to be declared as a dependency of the user's Angular module in order to be used.
Allow the configuration of a cache to be updated dynamically.
This way you won't have to destroy a cache and re-create it with new options in order to change the configuration. All of the current items in the cache will stay in the cache.
Any timers will start over beginning at the moment when the related options change.
AngularCache#info
already exists. This feature is to augment AngularCache#info
to accept one argument, the key for an item in the cache. If the item exists in the cache AngularCache#info
will return information about the item: when it was added, whether it has expired, etc.
The contents of a cache are correctly reset when the interval comes around, but it doesn't sync that change with web storage if the storageMode
option is used.
Show how to use $angularCacheFactory with the $http service, for example.
When trying to set aggressiveDelete
it passes a string when it should be a boolean
removeAll()
will call destroy()
on every cache owned by $angularCacheFactory
, and clearAll()
will call removeAll()
on every cache owned by $angularCacheFactory
.
In aggressive delete mode, this method eliminates a $timeout for every item in the cache and instead uses setInterval to sweep the cache for expired items. Setting this to 60000
for example, has the cache only checking for expired items once a minute, instead of the browser watching a timeout for every item in the cache.
Is it worth it to look into this?
After the major refactor of #57 all unit tests need to be re-written (most of them anyway).
$angularCacheFactoryProvider.setCacheDefaults(options)
$angularCacheFactory(cacheId, options)
$angularCacheFactory.get(cacheId)
$angularCacheFactory.removeAll()
$angularCacheFactory.clearAll()
$angularCacheFactory.info()
$angularCacheFactory.keys()
$angularCacheFactory.keySet()
AngularCache.put(key, value, options)
AngularCache.get(key, options)
AngularCache.remove(key, options)
AngularCache.removeExpired(options)
AngularCache.removeAll()
AngularCache.destroy()
AngularCache.info()
AngularCache.keys()
AngularCache.keySet()
BinaryHeap(weightFunc)
BinaryHeap.push(node)
BinaryHeap.pop()
BinaryHeap.peek()
BinaryHeap.remove(node)
BinaryHeap.removeAll()
Return an array of the keys associated with all current caches owned by the angularCacheFactory.
Hi,
It caused me some frustration until I finally traced it down. So let me explain:
When writing end-to-end tests using angular's new protractor webdriver the tests fail when you use aggressive delete option. The reason for that is that you use $timeout
service to remove caches after timeout as in here.
The way protractor works is that it waits for angular-known services like $http
, $q
, $timeout
and others to complete/resolve before executing next test statement to allow you not to set explicit timeouts in your tests. In other words it will wait for angular to complete before proceeding.
This causes protractor tests to fail with a timeout whenever you put to cache because it waits for your maxAge
timeout to resume testing.
You should remove the rev from the filenames in the dist directory, so your user's build scripts can rely on a consistent file name. See https://github.com/angular/bower-angular
Thanks for a great utility!
I have a situation, where I don't want the cache to immediately delete items that have expired. This is because I need to check if I can update the old item with a request to a third party service, if that third party service rejects my request, I need access to the old cached item and have the option to reset the expiry.
Any ideas on how to achieve that? I see that both passive and aggressive delete both deletes the item when it has been invalidated.
Is it possible to actively trigger cache refreshing of a specific $resource request?
Somehow maxAge isn't set.
The offending line is:
angular-cache/src/angular-cache.js
Line 557 in 7383686
they key is set, but data is an empty object.
Maybe we need to put in a null check for maxAge?
When using bower and grunt, if I do a bower update angular-cache and it now installed 1.1.0 instead of 1.0.0 it will break my grunt build, since that was using the path bower_components/angular-cache/dist/angular-cache-1.0.0.js
Since bower is the one in charge of versioning I think you can safely leave the version number out of the filename.
Create a roadmap that shows the plan leading up to a 1.0.0 release
Currently the bower installed one doesn't have the dist folder. Is it possible to provide this?
You guys should see if you fall into them https://github.com/angular/angular.js/wiki/Best-Practices
When an item expires, (or when it is discovered that an item has expired in passive mode), optionally specify a callback function to be executed, which will be passed the key-value pair of the expired item. For example:
var newCache = $angularCacheFactory('newCache', {
maxAge: 1000,
aggressiveDelete: true,
onExpire: function (key, value) {
// do something, e.g. retrieve a fresh copy of the expired item from the server
}
});
newCache.put('item1', 'foo');
// After 1 second, the "onExpire" function is executed.
// In this case, we don't have access to any return value from the "onExpire" callback, so don't rely on that.
This has to be handled differently:
var newCache = $angularCacheFactory('newCache', {
maxAge: 1000,
onExpire: function (key, value, done) {
// do something, e.g. retrieve a fresh copy of the expired item from the server
done(); // when done, call done() and pass whatever you want into it
}
});
newCache.put('item1', 'foo');
// ... wait 2 seconds
// Here it is discovered that item1 has expired, so it is deleted by angular-cache.
// Because an "onExpire" function was defined above, it is executed after item1 is deleted.
// Because this cache is in passive delete mode, we can capture a return value from the "onExpire" callback, which we couldn't do in aggressive delete mode.
// We capture the return value by passing in a callback to the get function, which is only executed if the item has expired.
$scope.item1 = newCache.get('item1', function (arg1, arg2, ...) {
// This callback is the "done" function executed by the "onExpire" callback above.
// Do something with whatever the "onExpire" callback gave to us.
});
With this feature, your cache can not only clear itself of expired items, but retrieve fresh copies as well (or whatever you want to do when the items expire).
Return the set of keys associated with all current caches owned by the angularCacheFactory.
The demo should show off all of angular-cache's features
Don't code while drowsy.
Hi there!
It might be nice to have an option to clear all caches without calling each one by name.
I think I can wrap cache factory to keep track of all the created caches but maybe there is such an option already?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.