Skip to content

Commit

Permalink
COLDBOX-1268 #resolve
Browse files Browse the repository at this point in the history
WireBox Singleton auto reload now only affects app singletons and not core singletons
  • Loading branch information
lmajano committed Feb 2, 2024
1 parent 418bbcf commit 268d394
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion system/Bootstrap.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ component serializable="false" accessors="true" {
// WireBox Singleton AutoReload
if ( cbController.getSetting( "Wirebox" ).singletonReload ) {
lock type="exclusive" name="#appHash#" timeout="#lockTimeout#" throwontimeout="true" {
cbController.getWireBox().clearSingletons();
cbController.getWireBox().clearAppSingletons();
}
}
// Handler's Index Auto Reload
Expand Down
8 changes: 8 additions & 0 deletions system/ioc/Injector.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,14 @@ component serializable="false" accessors="true" {
return this;
}

/**
* Clear the app singleton cache
*/
Injector function clearAppSingletons(){
getScope( "SINGLETON" ).clearAppOnly();
return this;
}

/**
* Return a self reference using the scoped registration, mostly used by providers or scope widening objects
*
Expand Down
30 changes: 30 additions & 0 deletions system/ioc/scopes/Singleton.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ component accessors="true" {
*/
property name="log";

/**
* These are keys we use internally in ColdBox, so we don't want to clear them when doing clearAppOnly() calls
*/
variables.RESERVED_KEYS = [ "@coldbox", "interceptor-", "cbscheduler", "@coreDelegates", "@cbdelegates" ];

/**
* Configure the scope for operation and returns itself
*
Expand Down Expand Up @@ -133,4 +138,29 @@ component accessors="true" {
return this;
}

/**
* Clear application only singletons
*/
function clearAppOnly(){
var keys = variables.singletons.keySet().toArray();
for( var key in keys ){
// They key must NOT match any pattern in our reserved keys, so we can clear it
if( !inReservedKeys( key ) ){
variables.singletons.remove( key );
}
}
return this;
}

/**
* Discover if a key is in our reserved keys
*
* @key The key to check
*
* @return boolean
*/
private boolean function inReservedKeys( String key ){
return variables.RESERVED_KEYS.some( ( reservedKey ) => findNoCase( reservedKey, key ) );
}

}
3 changes: 3 additions & 0 deletions test-harness/config/Coldbox.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,8 @@
}

function development(){
wirebox = {
singletonReload : true
}
}
}

0 comments on commit 268d394

Please sign in to comment.