Module bus.limiter

Class MethodProvider

java.lang.Object
org.miaixz.bus.limiter.metric.MethodProvider
All Implemented Interfaces:
Serializable, org.miaixz.bus.core.Provider, Provider

public class MethodProvider extends Object implements Provider
Implements the Provider interface for handling the HOT_METHOD strategy mode. This provider is responsible for caching method invocation results for a specified duration to optimize performance for frequently accessed methods (hot methods).
Since:
Java 17+
Author:
Kimi Liu
See Also:
  • Constructor Details

    • MethodProvider

      public MethodProvider()
      Constructs a new MethodProvider and initializes the timed cache. The cache's time-to-live (TTL) is determined by the seconds property loaded from the global Holder context. A pruning schedule is also set up to clean expired entries.
  • Method Details

    • get

      public StrategyMode get()
      Returns the strategy mode supported by this provider, which is StrategyMode.HOT_METHOD.
      Specified by:
      get in interface Provider
      Returns:
      The StrategyMode.HOT_METHOD enum value.
    • process

      public Object process(Object bean, Method method, Object[] args)
      Processes the method invocation by first checking if the result is available in the cache. If the result is cached and not expired, it is returned directly. Otherwise, the method is invoked, its result is stored in the cache, and then returned.
      Specified by:
      process in interface Provider
      Parameters:
      bean - The target object on which the method is invoked.
      method - The Method being invoked.
      args - The arguments passed to the method invocation.
      Returns:
      The result of the method invocation, either from cache or actual execution.