Skip to content

Commit

Permalink
cacheRegionRemove
Browse files Browse the repository at this point in the history
  • Loading branch information
lmajano committed May 7, 2024
1 parent 3b25011 commit d8c8a82
Showing 1 changed file with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* [BoxLang]
*
* Copyright [2023] [Ortus Solutions, Corp]
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
package ortus.boxlang.modules.compat.bifs.cache;

import ortus.boxlang.runtime.bifs.BIF;
import ortus.boxlang.runtime.bifs.BoxBIF;
import ortus.boxlang.runtime.context.IBoxContext;
import ortus.boxlang.runtime.scopes.ArgumentsScope;
import ortus.boxlang.runtime.scopes.Key;
import ortus.boxlang.runtime.types.Argument;
import ortus.boxlang.runtime.types.exceptions.BoxRuntimeException;

@BoxBIF
public class CacheRegionRemove extends BIF {

/**
* Constructor
*/
public CacheRegionRemove() {
super();
declaredArguments = new Argument[] {
new Argument( true, Argument.STRING, Key.region )
};
}

/**
* Checks if the cache region exists.
*
* @param context The context in which the BIF is being invoked.
* @param arguments Argument scope for the BIF.
*
* @argument.region The cache region to check for existence.
*
* @return True if the cache region exists, false otherwise.
*/
public Object _invoke( IBoxContext context, ArgumentsScope arguments ) {
Key cacheName = Key.of( arguments.getAsString( Key.region ) );

if ( cacheName.equals( Key._DEFAULT ) ) {
throw new BoxRuntimeException( "The default cache region cannot be removed." );
}

// Get the requested cache
if ( cacheService.hasCache( cacheName ) ) {
cacheService.shutdownCache( cacheName );
return true;
} else {
return false;
}
}
}

0 comments on commit d8c8a82

Please sign in to comment.