angular/angular.js — pull request #5203 by rainboxx (2013-11-29 16:56:25+00:00)
Title: feat($cacheFactory): add expiration option to $cacheFactory

Adds an option to $cacheFactory to define the expiration of a key after a given amount of elapsed milliseconds.

The change additionally alters the defaultCache for $http so that it can be configured during the run phase.

----

I'd like to discuss about this feature being implemented into the AngularJS core. I know there are more powerful cache factories out there and the cache factory of AngularJS should be simple and lightweight. However, for requests to a REST API it should be possible to automatically invalidate the results after a given amount of time, while everything is still simple and lightweight. So I added this small amount of code to the `$cacheFactory`.

Tests for the change in `src/ng/http.js` are missing since I don't know how to test this properly. Hopefully someone can tell me how this could be achieved or point me to the right direction and I'll add a test for that, too. The change has been implemented so one can configure the `defaultCache` with a `maxAge` as follows:

```javascript
'use strict';

angular.module('app', [
'ngResource'
])
.run(["$cacheFactory", function($cacheFactory) {
$cacheFactory('$http', { maxAge: 10000 });
}]);
```

Additionally I want to mention that the time for adding this change and pull request (as well as the upcoming test for the `$http` change) has been payed by PAYMILL GmbH, Munich. I have been asked whether this could be mentioned somewhere once the code gets approved but wouldn't be an obstacle. I and PAYMILL would like to see this code in AngularJS and is the primary goal of this PR.

P.S.: CLA already signed. Anything else missing?