Class NameMatchCacheOperationSource

java.lang.Object
org.springframework.cache.interceptor.NameMatchCacheOperationSource
All Implemented Interfaces:
Serializable, CacheOperationSource

public class NameMatchCacheOperationSource extends Object implements CacheOperationSource, Serializable
Simple CacheOperationSource implementation that allows attributes to be matched by registered name.
Since:
3.1
Author:
Costin Leau
See Also:
  • Field Details

    • logger

      protected static final Log logger
      Logger available to subclasses.

      Static for optimal serialization.

  • Constructor Details

    • NameMatchCacheOperationSource

      public NameMatchCacheOperationSource()
  • Method Details

    • setNameMap

      public void setNameMap(Map<String,Collection<CacheOperation>> nameMap)
      Set a name/attribute map, consisting of method names (e.g. "myMethod") and CacheOperation instances (or Strings to be converted to CacheOperation instances).
      See Also:
    • addCacheMethod

      public void addCacheMethod(String methodName, Collection<CacheOperation> ops)
      Add an attribute for a cacheable method.

      Method names can be exact matches, or of the pattern "xxx*", "*xxx" or "*xxx*" for matching multiple methods.

      Parameters:
      methodName - the name of the method
      ops - operation associated with the method
    • getCacheOperations

      @Nullable public Collection<CacheOperation> getCacheOperations(Method method, @Nullable Class<?> targetClass)
      Description copied from interface: CacheOperationSource
      Return the collection of cache operations for this method, or null if the method contains no cacheable annotations.
      Specified by:
      getCacheOperations in interface CacheOperationSource
      Parameters:
      method - the method to introspect
      targetClass - the target class (can be null, in which case the declaring class of the method must be used)
      Returns:
      all cache operations for this method, or null if none found
    • isMatch

      protected boolean isMatch(String methodName, String mappedName)
      Return if the given method name matches the mapped name.

      The default implementation checks for "xxx*", "*xxx" and "*xxx*" matches, as well as direct equality. Can be overridden in subclasses.

      Parameters:
      methodName - the method name of the class
      mappedName - the name in the descriptor
      Returns:
      if the names match
      See Also:
    • equals

      public boolean equals(@Nullable Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object