Package ortus.boxlang.runtime.services
Class CacheService
java.lang.Object
ortus.boxlang.runtime.services.BaseService
ortus.boxlang.runtime.services.CacheService
- All Implemented Interfaces:
IService
This is a service that provides caching functionality to BoxLang.
It is a core service and is started up when the runtime starts.
It consists on the ability to register/build cache providers
that can be used anywhere in BoxLang.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Class<CoreProviderType> -------------------------------------------------------------------------- Public Properties --------------------------------------------------------------------------Fields inherited from class ortus.boxlang.runtime.services.BaseService
name, runtime, timerUtil -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidClear all elements in all cachescreateCache(String name, String provider, IStruct properties) Create a new cache according to the name, provider and properties structurecreateCache(Key name, Key provider, IStruct properties) Create a new cache according to the name, provider and properties structurecreateCacheIfAbsent(Key name, Key provider, IStruct properties) Create a new cache if not found according to the name.createDefaultCache(String name) Create a new named default cache, register it and return it.createDefaultCache(String name, CacheConfig config) Create a new named default cache with a custom config, register it and return it.createDefaultCache(Key name) Create a new named default cache, register it and return it.createDefaultCache(Key name, CacheConfig config) Create a new named default cache with a custom config, register it and return it.Get a reference to a registered cache provider.Get a reference to a registered cache provider.Get back the default cacheClass<? extends ICacheProvider> getProvider(String provider) Get the requested provider by name or throw an exception if it does not existClass<? extends ICacheProvider> getProvider(Key provider) Get the requested provider by name or throw an exception if it does not existGet all the registered caches back as an array of stringsGet an array of registered providers as stringsGet the scheduled executor service assigned to all caching servicesbooleanVerify if we have a cache registered with the given namebooleanVerify if we have a cache registered with the given namebooleanhasProvider(String provider) Check if a provider existsbooleanhasProvider(Key provider) Check if a provider existsvoidThe configuration load event is fired when the runtime loads the configurationvoidonShutdown(Boolean force) The shutdown event is fired when the runtime shuts downvoidThe startup event is fired when the runtime starts up This will create all the core caches and register themvoidReap all elements in all cachesregisterCache(ICacheProvider provider) This registers an ICacheProvider with the CacheService and links it to the service.registerProvider(String name, Class<? extends ICacheProvider> provider) Register a new cache provider If the provider already exists, it will throw an exceptionregisterProvider(Key name, Class<? extends ICacheProvider> provider) Register a new cache provider If the provider already exists, it will throw an exceptionvoidThis removes all caches from the cache service and triggers a shutdown on each of them The CacheService will be left in a state where it has no caches registered.booleanremoveProvider(String name) Remove a registered provider by name If the provider does not exist, it will skip outbooleanremoveProvider(Key name) Remove a registered provider by name If the provider does not exist, it will skip outreplaceCache(String name, ICacheProvider newProvider) Replace a registered cache with a new one of the same name that's already configured and ready to go.replaceCache(Key name, ICacheProvider newProvider) Replace a registered cache with a new one of the same name that's already configured and ready to go.voidshutdownCache(Key name) Shutdown a cache by name and remove it from the registry.Methods inherited from class ortus.boxlang.runtime.services.BaseService
announce, announce, announce, announce, getName, getRuntime, getTimerUtil
-
Field Details
-
CORE_TYPES
-------------------------------------------------------------------------- Public Properties --------------------------------------------------------------------------
-
-
Constructor Details
-
CacheService
Constructor- Parameters:
runtime- The runtime instance
-
-
Method Details
-
getTaskScheduler
Get the scheduled executor service assigned to all caching services- Returns:
- The scheduled executor record
-
onConfigurationLoad
public void onConfigurationLoad()The configuration load event is fired when the runtime loads the configuration- Specified by:
onConfigurationLoadin interfaceIService- Overrides:
onConfigurationLoadin classBaseService
-
onStartup
public void onStartup()The startup event is fired when the runtime starts up This will create all the core caches and register them- Specified by:
onStartupin interfaceIService- Specified by:
onStartupin classBaseService
-
onShutdown
The shutdown event is fired when the runtime shuts down- Specified by:
onShutdownin interfaceIService- Specified by:
onShutdownin classBaseService- Parameters:
force- True if the shutdown is forced
-
shutdownCache
Shutdown a cache by name and remove it from the registry. If the cache does not exist, it will skip out.- Parameters:
name- The name of the cache
-
getCache
Get a reference to a registered cache provider. If the cache provider does not exist, it will throw an exception.- Parameters:
name- The name of the cache- Returns:
- The cache provider
- Throws:
BoxRuntimeException- If the cache does not exist
-
getCache
Get a reference to a registered cache provider. If the cache provider does not exist, it will throw an exception.- Parameters:
name- The name of the cache- Returns:
- The cache provider
- Throws:
BoxRuntimeException- If the cache does not exist
-
getDefaultCache
Get back the default cache- Returns:
- The default cache
-
hasCache
Verify if we have a cache registered with the given name- Parameters:
name- The name of the cache- Returns:
- True if the cache is registered, false otherwise
-
hasCache
Verify if we have a cache registered with the given name- Parameters:
name- The name of the cache- Returns:
- True if the cache is registered, false otherwise
-
replaceCache
Replace a registered cache with a new one of the same name that's already configured and ready to go.- Parameters:
name- The name of the cache to replacenewProvider- The new cache provider- Returns:
- The CacheService
-
replaceCache
Replace a registered cache with a new one of the same name that's already configured and ready to go.- Parameters:
name- The name of the cache to replacenewProvider- The new cache provider- Returns:
- The CacheService
-
registerCache
This registers an ICacheProvider with the CacheService and links it to the service. It will also announce the registration of the cache. It's your job to make sure the cache is ready to go.- Parameters:
provider- The cache provider to register- Throws:
BoxRuntimeException- If a cache with the same name already exists
-
createDefaultCache
Create a new named default cache, register it and return it.- Parameters:
name- The name of the cache- Returns:
- The created and registered cache
-
createDefaultCache
Create a new named default cache, register it and return it.- Parameters:
name- The name of the cache- Returns:
- The created and registered cache
-
createDefaultCache
Create a new named default cache with a custom config, register it and return it.- Parameters:
name- The name of the cacheconfig- The cache configuration- Returns:
- The created and registered cache
-
createDefaultCache
Create a new named default cache with a custom config, register it and return it.- Parameters:
name- The name of the cacheconfig- The cache configuration- Returns:
- The created and registered cache
-
getRegisteredCaches
Get all the registered caches back as an array of strings- Returns:
- The registered caches as an array of strings
-
createCache
Create a new cache according to the name, provider and properties structure- Parameters:
name- The name of the cacheprovider- A valid cache providerproperties- The properties to configure the cache- Returns:
- The created and registered cache
-
createCacheIfAbsent
Create a new cache if not found according to the name.- Parameters:
name- The name of the cacheprovider- A valid cache providerproperties- The properties to configure the cache- Returns:
- The previously registered cache or the newly created one
-
createCache
Create a new cache according to the name, provider and properties structure- Parameters:
name- The name of the cacheprovider- A valid cache providerproperties- The properties to configure the cache- Returns:
- The created and registered cache
-
getRegisteredProviders
Get an array of registered providers as strings -
hasProvider
Check if a provider exists- Parameters:
provider- The provider to check
-
hasProvider
Check if a provider exists- Parameters:
provider- The provider to check
-
getProvider
Get the requested provider by name or throw an exception if it does not exist- Parameters:
provider- The name of the provider- Returns:
- The provider class
-
getProvider
Get the requested provider by name or throw an exception if it does not exist- Parameters:
provider- The name of the provider- Returns:
- The provider class
-
registerProvider
Register a new cache provider If the provider already exists, it will throw an exception- Parameters:
name- The name of the providerprovider- The provider class- Returns:
- The CacheService
-
registerProvider
Register a new cache provider If the provider already exists, it will throw an exception- Parameters:
name- The name of the providerprovider- The provider class- Returns:
- The CacheService
-
removeProvider
Remove a registered provider by name If the provider does not exist, it will skip out- Parameters:
name- The name of the provider- Returns:
- True if the provider was removed, false otherwise
-
removeProvider
Remove a registered provider by name If the provider does not exist, it will skip out- Parameters:
name- The name of the provider- Returns:
- True if the provider was removed, false otherwise
-
removeAllCaches
public void removeAllCaches()This removes all caches from the cache service and triggers a shutdown on each of them The CacheService will be left in a state where it has no caches registered. -
clearAllCaches
public void clearAllCaches()Clear all elements in all caches -
reapAllCaches
public void reapAllCaches()Reap all elements in all caches
-