-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.html
92 lines (81 loc) · 2.92 KB
/
example.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<!DOCTYPE html>
<html>
<head>
<!-- generic unused meta -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
<!-- application title -->
<title>Cachomatic Example</title>
</head>
<body ng-app="example.app">
<p>Open Console To View Output</p>
<!-- example js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.0/angular.js"></script>
<script src="./release/cachomatic.js"></script>
<script type="text/javascript">
/**
* @description
* Example app module declaration.
*/
angular
.module('example.app', [
// Make sure to include the cachomatic module
'sbb.cachomatic'
])
.config([
'CachomaticProvider',
Config
])
.run([
'Cachomatic',
Bootstrap
])
/**
* @name Config
* @description
* This function will configure the application as needed.
*
* @param {sbb.cachomatic} CachomaticProvider
*/
function Config(CachomaticProvider) {
// Example cache key prefix to prevent collision
CachomaticProvider.setCachePrefix('cacheKey');
}
/**
* @name Bootstrap
* @description
* This function will bootstrap the application as needed.
*
* @param {sbb.cachomatic} Cachomatic
*/
function Bootstrap(Cachomatic) {
// Display the cache key prefix
console.log('[Cachomatic] prefix =>', Cachomatic.getCachePrefix());
// Set a cache string value with no expiration
var value = 'awesome';
console.log('[Cachomatic] set =>', value);
Cachomatic.set('example-key', value);
// Retrieve the set cache value
console.log('[Cachomatic] get =>', Cachomatic.get('example-key'));
// Set a cache object value with no expiration
var objValue = { cache: 'is awesome' };
console.log('[Cachomatic] set =>', objValue);
Cachomatic.setObject('example-obj-key', objValue);
// Retrieve the set cache value
console.log('[Cachomatic] get =>', Cachomatic.getObject('example-obj-key'));
// Check to see if a cache value exists
console.log('[Cachomatic] "example-obj-key" exists =>', Cachomatic.exists('example-obj-key'));
console.log('[Cachomatic] "non-existent-key" exists =>', Cachomatic.exists('non-existent-key'));
// Clear a specific cache key
Cachomatic.clear('example-key');
console.log('[Cachomatic] "example-key" cleared =>', !Cachomatic.exists('example-key'));
// Clear the rest of the cache
Cachomatic.clearAll();
console.log(
'[Cachomatic] cache cleared =>',
!Cachomatic.exists('example-obj-key') && !Cachomatic.exists('example-key')
);
}
</script>
</body>
</html>