-
-
Notifications
You must be signed in to change notification settings - Fork 171
/
Copy patheventcaching.cfc
95 lines (82 loc) · 2.18 KB
/
eventcaching.cfc
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
93
94
95
component output = "false" singleton{
/**
* clear all event caching for tests.
*/
function clearAll( event, rc, prc ){
getCache( "template" ).clearEvent( "eventcaching.index" );
return cacheKeys( argumentCollection = arguments );
}
/**
* clear all for json
*/
function clearJSON( event, rc, prc ){
getCache( "template" ).clearEvent( "eventcaching.index", "format=json" );
return cacheKeys( argumentCollection = arguments );
}
function clearPartial( event, rc, prc ){
getCache( "template" ).clearEvent( "eventcaching" );
return cacheKeys( argumentCollection = arguments );
}
// Default Action
function index( event, rc, prc ) cache="true" cacheTimeout="10"{
prc.data = [
{ id : createUUID(), name : "luis" },
{ id : createUUID(), name : "lucas" },
{ id : createUUID(), name : "fernando" }
];
event.renderData( data = prc.data, formats = "json,xml,pdf,html" );
}
// With Provider
function withProvider( event, rc, prc )
cache ="true"
cacheTimeout ="10"
cacheProvider="default"
{
prc.data = [
{ id : createUUID(), name : "luis" },
{ id : createUUID(), name : "lucas" },
{ id : createUUID(), name : "fernando" }
];
return prc.data;
}
function cacheKeys( event, rc, prc ){
var keys = {
"template" : getCache( "template" ).getKeys(),
"default" : getCache( "default" ).getKeys()
};
return keys;
}
// widget event
function widget( event, rc, prc, widget = true ){
var data = [
{ id : createUUID(), name : "luis" },
{ id : createUUID(), name : "lucas" },
{ id : createUUID(), name : "fernando" }
];
return { data : data, timestamp : now() };
}
/**
* Produces a non-throwing error by setting the status code to 500,
* This should not cache the output
*/
function produceError( event, rc, prc ) cache="true" cacheTimeout="10"{
event.setHTTPHeader( statusCode = 500 );
return {
error : false,
messages : "Test",
when : now()
};
}
function produceRenderData( event, rc, prc ) cache="True" cachetimeout="5"{
var data = {
error : false,
messages : "Test",
when : now()
};
event.renderData(
type = "json",
data = data,
statusCode = 500
);
}
}