Class CacheService

java.lang.Object
ortus.boxlang.runtime.services.BaseService
ortus.boxlang.runtime.services.CacheService
All Implemented Interfaces:
IService

public class CacheService extends BaseService
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 Details

    • CORE_TYPES

      public static final Class<CoreProviderType> CORE_TYPES
      -------------------------------------------------------------------------- Public Properties --------------------------------------------------------------------------
  • Constructor Details

    • CacheService

      public CacheService(BoxRuntime runtime)
      Constructor
      Parameters:
      runtime - The runtime instance
  • Method Details

    • getTaskScheduler

      public BoxExecutor 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:
      onConfigurationLoad in interface IService
      Overrides:
      onConfigurationLoad in class BaseService
    • 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:
      onStartup in interface IService
      Specified by:
      onStartup in class BaseService
    • onShutdown

      public void onShutdown(Boolean force)
      The shutdown event is fired when the runtime shuts down
      Specified by:
      onShutdown in interface IService
      Specified by:
      onShutdown in class BaseService
      Parameters:
      force - True if the shutdown is forced
    • shutdownCache

      public void shutdownCache(Key name)
      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

      public ICacheProvider getCache(String name)
      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

      public ICacheProvider getCache(Key name)
      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

      public ICacheProvider getDefaultCache()
      Get back the default cache
      Returns:
      The default cache
    • hasCache

      public boolean hasCache(String name)
      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

      public boolean hasCache(Key name)
      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

      public CacheService replaceCache(String name, ICacheProvider newProvider)
      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 replace
      newProvider - The new cache provider
      Returns:
      The CacheService
    • replaceCache

      public CacheService 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.
      Parameters:
      name - The name of the cache to replace
      newProvider - The new cache provider
      Returns:
      The CacheService
    • registerCache

      public ICacheProvider registerCache(ICacheProvider provider)
      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

      public ICacheProvider createDefaultCache(String name)
      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

      public ICacheProvider createDefaultCache(Key name)
      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

      public ICacheProvider createDefaultCache(String name, CacheConfig config)
      Create a new named default cache with a custom config, register it and return it.
      Parameters:
      name - The name of the cache
      config - The cache configuration
      Returns:
      The created and registered cache
    • createDefaultCache

      public ICacheProvider createDefaultCache(Key name, CacheConfig config)
      Create a new named default cache with a custom config, register it and return it.
      Parameters:
      name - The name of the cache
      config - The cache configuration
      Returns:
      The created and registered cache
    • getRegisteredCaches

      public Array getRegisteredCaches()
      Get all the registered caches back as an array of strings
      Returns:
      The registered caches as an array of strings
    • createCache

      public ICacheProvider createCache(String name, String provider, IStruct properties)
      Create a new cache according to the name, provider and properties structure
      Parameters:
      name - The name of the cache
      provider - A valid cache provider
      properties - The properties to configure the cache
      Returns:
      The created and registered cache
    • createCacheIfAbsent

      public ICacheProvider createCacheIfAbsent(Key name, Key provider, IStruct properties)
      Create a new cache if not found according to the name.
      Parameters:
      name - The name of the cache
      provider - A valid cache provider
      properties - The properties to configure the cache
      Returns:
      The previously registered cache or the newly created one
    • createCache

      public ICacheProvider createCache(Key name, Key provider, IStruct properties)
      Create a new cache according to the name, provider and properties structure
      Parameters:
      name - The name of the cache
      provider - A valid cache provider
      properties - The properties to configure the cache
      Returns:
      The created and registered cache
    • getRegisteredProviders

      public Array getRegisteredProviders()
      Get an array of registered providers as strings
    • hasProvider

      public boolean hasProvider(String provider)
      Check if a provider exists
      Parameters:
      provider - The provider to check
    • hasProvider

      public boolean hasProvider(Key provider)
      Check if a provider exists
      Parameters:
      provider - The provider to check
    • getProvider

      public Class<? extends ICacheProvider> getProvider(String provider)
      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

      public Class<? extends ICacheProvider> getProvider(Key provider)
      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

      public CacheService registerProvider(String name, Class<? extends ICacheProvider> provider)
      Register a new cache provider If the provider already exists, it will throw an exception
      Parameters:
      name - The name of the provider
      provider - The provider class
      Returns:
      The CacheService
    • registerProvider

      public CacheService registerProvider(Key name, Class<? extends ICacheProvider> provider)
      Register a new cache provider If the provider already exists, it will throw an exception
      Parameters:
      name - The name of the provider
      provider - The provider class
      Returns:
      The CacheService
    • removeProvider

      public boolean removeProvider(String name)
      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

      public boolean removeProvider(Key name)
      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