Skip to content

Commit 38350d7

Browse files
committed
New documentation.
1 parent 8b69e82 commit 38350d7

19 files changed

+895
-284
lines changed

Gruntfile.js

+46-20
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,15 @@ module.exports = function (grunt) {
195195
groupIcon: 'icon-book',
196196
sections: [
197197
{
198-
id: 'overview',
199-
title: 'Overview',
200-
docs: ['guide/overview/'],
198+
id: 'angular-data',
199+
title: 'angular-data',
200+
docs: [
201+
'guide/angular-data/index.doc',
202+
'guide/angular-data/overview.doc',
203+
'guide/angular-data/resources.doc',
204+
'guide/angular-data/synchronous.doc',
205+
'guide/angular-data/asynchronous.doc'
206+
],
201207
rank: {
202208
index: 1,
203209
overview: 2,
@@ -207,9 +213,21 @@ module.exports = function (grunt) {
207213
}
208214
},
209215
{
210-
id: 'resource',
216+
id: 'angular-cache',
217+
title: 'angular-cache',
218+
docs: ['guide/angular-cache/'],
219+
rank: {
220+
index: 1,
221+
basics: 2,
222+
configure: 3,
223+
http: 4,
224+
storage: 5
225+
}
226+
},
227+
{
228+
id: 'angular-data-resource',
211229
title: 'Defining Resources',
212-
docs: ['guide/resource/'],
230+
docs: ['guide/angular-data/resource/'],
213231
rank: {
214232
index: 1,
215233
overview: 2,
@@ -219,18 +237,18 @@ module.exports = function (grunt) {
219237
}
220238
},
221239
{
222-
id: 'queries',
240+
id: 'angular-data-queries',
223241
title: 'Queries',
224-
docs: ['guide/queries/'],
242+
docs: ['guide/angular-data/queries/'],
225243
rank: {
226244
index: 1,
227245
overview: 2
228246
}
229247
},
230248
{
231-
id: 'adapters',
249+
id: 'angular-data-adapters',
232250
title: 'Adapters',
233-
docs: ['guide/adapters/'],
251+
docs: ['guide/angular-data/adapters/'],
234252
rank: {
235253
index: 1,
236254
overview: 2
@@ -245,12 +263,20 @@ module.exports = function (grunt) {
245263
showSource: true,
246264
sections: [
247265
{
248-
id: 'api',
266+
id: 'angular-data',
249267
title: 'angular-data',
250268
scripts: [
251269
'src/'
252270
],
253271
docs: ['guide/api']
272+
},
273+
{
274+
id: 'angular-cache',
275+
title: 'angular-cache',
276+
scripts: [
277+
'../angular-cache/dist/angular-cache.js'
278+
],
279+
docs: ['guide/api']
254280
}
255281
]
256282
}
@@ -260,16 +286,16 @@ module.exports = function (grunt) {
260286
showAngularDocs: false,
261287
docular_partial_home: 'guide/home.html',
262288
docular_partial_navigation: 'guide/nav.html',
263-
docular_partial_footer: 'guide/footer.html',
264-
analytics: {
265-
account: 'UA-46792694-5',
266-
domainName: 'angular-data.codetrain.io'
267-
},
268-
discussions: {
269-
shortName: 'angular-data',
270-
url: 'http://angular-data.codetrain.io',
271-
dev: dev
272-
}
289+
docular_partial_footer: 'guide/footer.html'//,
290+
// analytics: {
291+
// account: 'UA-46792694-5',
292+
// domainName: 'angular-cache.codetrain.io'
293+
// },
294+
// discussions: {
295+
// shortName: 'angular-data',
296+
// url: 'http://angular-cache.codetrain.io',
297+
// dev: dev
298+
// }
273299
}
274300
});
275301

guide/angular-cache/basics.doc

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
@doc overview
2+
@id basics
3+
@name Basics
4+
@description
5+
6+
## Create a cache
7+
First, inject `$angularCacheFactory` then create as many caches as you so desire. Let's go:
8+
9+
```javascript
10+
app.service('myService', function ($angularCacheFactory) {
11+
12+
// Create a new cache called "profileCache"
13+
var profileCache = $angularCacheFactory('profileCache');
14+
});
15+
```
16+
17+
Let's add some items to the cache:
18+
19+
```javascript
20+
profileCache.put('/profiles/34', {
21+
name: 'John',
22+
skills: ['programming', 'piano']
23+
});
24+
25+
profileCache.put('/profiles/22', {
26+
name: 'Sally',
27+
skills: ['marketing', 'climbing', 'painting']
28+
});
29+
```
30+
31+
Right now, these items will stay in the cache indefinitely. What if, for the sake of the example, I know that users change their skills in their profile once a week. The profile information is subject to change, but we don't want to make tons of requests for profiles that probably haven't changed.
32+
33+
Let's have items which are added to `profileCache` expire after an hour:
34+
35+
```javascript
36+
profileCache.setOptions({
37+
maxAge: 3600000
38+
});
39+
```
40+
41+
Perfect. Say we also want the items removed from the cache when they expire:
42+
43+
```javascript
44+
profileCache.setOptions({
45+
deleteOnExpire: 'aggressive'
46+
});
47+
```
48+
49+
Let's say that when the items do expire, we want to refresh them with new values:
50+
51+
```javascript
52+
profileCache.setOptions({
53+
onExpire: function (key, value) {
54+
$http.get(key).success(function (data) {
55+
profileCache.put(key, data);
56+
});
57+
}
58+
});
59+
```
60+
61+
Sweet! Now we'd probably have configured our cache correctly when we created it:
62+
63+
```javascript
64+
var profileCache = $angularCacheFactory('profileCache', {
65+
maxAge: 3600000,
66+
deleteOnExpire: 'aggressive',
67+
onExpire: function (key, value) {
68+
$http.get(key).success(function (data) {
69+
profileCache.put(key, data);
70+
});
71+
}
72+
});
73+
```
74+
75+
Or say we want all of our caches to use that configuration as their default:
76+
77+
```javascript
78+
angular.module('app', ['jmdobry.angular-cache'])
79+
.config(function ($angularCacheFactoryProvider) {
80+
81+
$angularCacheFactoryProvider.setCacheDefaults({
82+
maxAge: 3600000,
83+
deleteOnExpire: 'aggressive',
84+
onExpire: function (key, value) {
85+
$http.get(key).success(function (data) {
86+
profileCache.put(key, data);
87+
});
88+
}
89+
});
90+
});
91+
```
92+
93+
## Working with a cache
94+
We can retrieve items from a cache like so:
95+
96+
```javascript
97+
var profile = profileCache.get('/profiles/34');
98+
99+
profile.name; // 'John'
100+
```
101+
102+
And get information about items in the cache:
103+
104+
```javascript
105+
var info = profileCache.info('/profiles/34');
106+
107+
info.isExpired; // false
108+
// etc.
109+
```
110+
111+
and information about the cache itself:
112+
113+
```javascript
114+
var info = profileCache.info();
115+
116+
info.size; // 2
117+
info.maxAge; // 3600000
118+
info.deleteOnExpire; // 'aggressive'
119+
// etc.
120+
```
121+
122+
Items are easily removed, and we can destroy out cache when we're done with it:
123+
124+
```javascript
125+
profileCache.remove('/profiles/34');
126+
127+
profileCache.get('/profiles/34'); // undefined
128+
129+
profileCache.destroy();
130+
131+
$angularCacheFactory.get('profileCache'); // undefined
132+
```
133+
134+
See the [API Documentation](api.html) for more information on the available methods.

guide/angular-cache/configure.doc

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
@doc overview
2+
@id configure
3+
@name Configure a cache
4+
@description
5+
6+
See [Configuration Options](configuration.html) for information on the available configuration options.
7+
8+
#### Dynamically configure a cache
9+
```javascript
10+
app.service('myService', function ($angularCacheFactory) {
11+
12+
var cache = $angularCacheFactory('cache', {
13+
capacity: 100,
14+
maxAge: 300000
15+
});
16+
17+
// Add 50 items here, for example
18+
19+
cache.info(); // { ..., size: 50, capacity: 100, maxAge: 300000, ... }
20+
21+
cache.setOptions({
22+
capacity: 30
23+
});
24+
25+
cache.info(); // { ..., size: 30, capacity: 30, maxAge: 300000, ... }
26+
// notice that only the 30 most recently added items remain in the cache because
27+
// the capacity was reduced.
28+
29+
// setting the second parameter to true will cause the cache's configuration to be
30+
// reset to defaults before the configuration passed into setOptions() is applied to
31+
// the cache
32+
cache.setOptions({
33+
cacheFlushInterval: 5500
34+
}, true);
35+
36+
cache.info(); // { ..., size: 30, cacheFlushInterval: 5500,
37+
// capacity: 1.7976931348623157e+308, maxAge: null, ... }
38+
39+
cache.put('someItem', 'someValue', { maxAge: 12000, deleteOnExpire: 'aggressive' });
40+
cache.info('someItem'); // { maxAge: 12000, deleteOnExpire: 'aggressive', isExpired: false, ... }
41+
});
42+
```
43+
See [AngularCache.setOptions(options)](api.html#cachesetoptions).

0 commit comments

Comments
 (0)