-
-
Notifications
You must be signed in to change notification settings - Fork 172
/
Copy pathColdboxCacheFlash.cfc
84 lines (71 loc) · 1.95 KB
/
ColdboxCacheFlash.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
/**
* Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
* www.ortussolutions.com
* ---
* This flash uses CacheBox
*
* @author Luis Majano <lmajano@ortussolutions.com>
*/
component extends="coldbox.system.web.flash.AbstractFlashScope" accessors="true" {
// The cahe name used
property name="cacheName";
// The cache provider
property name="cache";
/**
* Constructor
*
* @controller.hint ColdBox Controller
* @defaults.hint Default flash data packet for the flash RAM object=[scope,properties,inflateToRC,inflateToPRC,autoPurge,autoSave]
*/
function init( required controller, required struct defaults = {} ){
// default cache name
variables.cacheName = "default";
variables.appName = application.applicationname;
// super init
super.init( argumentCollection = arguments );
// Check if name exists in property
if ( propertyExists( "cacheName" ) ) {
variables.cacheName = getProperty( "cacheName" );
}
// Setup the cache
variables.cache = arguments.controller.getCache( variables.cacheName );
return this;
}
/**
* Build Flash Key according to our user tracking identifiers
*/
function getFlashKey(){
return "cbFlash:#getController().getUserSessionIdentifier()#";
}
/**
* Save the flash storage in preparing to go to the next request
*
* @return SessionFlash
*/
function saveFlash(){
variables.cache.set( getFlashKey(), getScope(), 2 );
return this;
}
/**
* Checks if the flash storage exists and IT HAS DATA to inflate.
*/
boolean function flashExists(){
return variables.cache.lookup( getFlashKey() );
}
/**
* Get the flash storage structure to inflate it.
*/
struct function getFlash(){
var results = variables.cache.get( getFlashKey() );
return isNull( local.results ) ? {} : results;
}
/**
* Remove the entire flash storage
*
* @return SessionFlash
*/
function removeFlash(){
variables.cache.clear( getFlashKey() );
return this;
}
}