Skip to content

Commit e2dceda

Browse files
committed
new example
1 parent 8534277 commit e2dceda

5 files changed

Lines changed: 91 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
exports.install = function(framework) {
2+
framework.route('/', view);
3+
framework.route('/json/', json);
4+
framework.route('/plain/', plain);
5+
};
6+
7+
function view() {
8+
9+
var self = this;
10+
self.repository.ticks = new Date().getTime();
11+
12+
// Save a rendered HTML into the cache (only the view - without layout, layout is not cached)
13+
// Documentation: http://docs.totaljs.com/FrameworkController/#controller.memorize
14+
// Memorize uses standard internal FrameworkCache
15+
self.memorize('view', new Date().add('minute', 2), function() {
16+
self.view('homepage', self.repository.ticks);
17+
});
18+
19+
}
20+
21+
function json() {
22+
23+
var self = this;
24+
25+
// Save a generated JSON into the cache
26+
// Documentation: http://docs.totaljs.com/FrameworkController/#controller.memorize
27+
// Memorize uses standard internal FrameworkCache
28+
self.memorize('json', new Date().add('minute', 2), function() {
29+
self.json({ ticks: new Date().getTime() });
30+
});
31+
}
32+
33+
function plain() {
34+
35+
var self = this;
36+
37+
// Save a output into the cache
38+
// Documentation: http://docs.totaljs.com/FrameworkController/#controller.memorize
39+
// Memorize uses standard internal FrameworkCache
40+
self.memorize('plain', new Date().add('minute', 2), function() {
41+
self.plain('ticks: ' + new Date().getTime());
42+
});
43+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
exports.install = function(framework) {
2+
framework.route('/users/', view_users);
3+
};
4+
5+
exports.models = {
6+
users: ['Peter', 'Lucia', 'Zuzana', 'Veronika']
7+
};
8+
9+
exports.functions = {
10+
exists: function(name) {
11+
return exports.models.users.indexOf(name) > -1;
12+
}
13+
};
14+
15+
function view_users() {
16+
this.json(exports.models.users);
17+
}

controller-memorize/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var framework = require('total.js');
2+
var http = require('http');
3+
var debug = true;
4+
5+
framework.run(http, debug);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Memorize</title>
5+
<meta charset="utf-8" />
6+
<meta http-equiv="X-UA-Compatible" content="IE=10" />
7+
<meta name="format-detection" content="telephone=no"/>
8+
<meta name="viewport" content="width=1024, user-scalable=yes" />
9+
<meta name="robots" content="all,follow" />
10+
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
11+
<style type="text/css">
12+
body { padding: 50px; margin: 0; font:normal 12px Arial; color: gray }
13+
a { float:left; margin: 0 5px 0 0; font-size: 13px; }
14+
p { background-color: #F0F0F0; padding: 5px; font:bold 15px Arial; }
15+
</style>
16+
</head>
17+
<body>
18+
<div>In layout: @{repository.ticks}</div>
19+
@{body}
20+
21+
<script type="text/javascript">
22+
setTimeout(function() { window.location.href = window.location.href }, 1000);
23+
</script>
24+
</body>
25+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div>In view: @{model} (cached)</div>

0 commit comments

Comments
 (0)