Class RuleCache

java.lang.Object
com.beassolution.rule.engine.cache.RuleCache

@Component public final class RuleCache extends Object
Cache for compiled rule expressions.

This class provides a thread-safe cache for storing compiled MVEL expressions that represent rules in the Beas Rule Engine. The cache improves performance by avoiding re-compilation of rules on each execution.

Key features include:

  • Thread-safe operations using ConcurrentHashMap
  • Compiled MVEL expressions storage
  • Bulk operations support
  • Cache management operations
Since:
1.0
Version:
1.0
Author:
Beas Solution Team
  • Constructor Details

    • RuleCache

      public RuleCache()
  • Method Details

    • put

      public void put(String key, Serializable instance)
      Stores a compiled rule expression in the cache.
      Parameters:
      key - The rule name
      instance - The compiled MVEL expression
    • putAll

      public void putAll(Map<String,Serializable> map)
      Stores multiple compiled rule expressions in the cache.
      Parameters:
      map - Map containing rule names and compiled expressions
    • get

      public Optional<Serializable> get(String key)
      Retrieves a compiled rule expression from the cache.
      Parameters:
      key - The rule name
      Returns:
      Optional containing the compiled expression if found
    • remove

      public void remove(String key)
      Removes a compiled rule expression from the cache.
      Parameters:
      key - The rule name to remove
    • clear

      public void clear()
      Clears all compiled rule expressions from the cache.

      This method removes all entries from the cache, typically used during cache synchronization or system reset.

    • getAll

      public Map<String,Serializable> getAll()
      Retrieves all cached rule expressions.
      Returns:
      Immutable copy of all cached expressions
    • contains

      public boolean contains(String key)
      Checks if a rule expression is cached.
      Parameters:
      key - The rule name to check
      Returns:
      true if the rule is cached, false otherwise