Class DTOAwareFieldResolutionCache

java.lang.Object
in.co.akshitbansal.springwebquery.resolver.field.cache.DTOAwareFieldResolutionCache

public class DTOAwareFieldResolutionCache extends Object
Shared cache for DTO-aware field-resolution outcomes.

Successful resolutions are retained without eviction, while failed resolutions are stored in a bounded cache to avoid unbounded memory growth from repeated invalid selector lookups.

  • Constructor Details

    • DTOAwareFieldResolutionCache

      public DTOAwareFieldResolutionCache(int failedResolutionsMaxCapacity, int lockStripeCount)
      Creates the shared cache used by cached DTO-aware field resolvers.
      Parameters:
      failedResolutionsMaxCapacity - maximum number of failed resolutions to retain
      lockStripeCount - number of lock stripes used to coordinate cache population for selector keys
      Throws:
      IllegalArgumentException - if the failed-resolution cache capacity or lock stripe count is non-positive
  • Method Details

    • resolveFromCache

      public @Nullable ResolutionResult resolveFromCache(@NonNull @NonNull CacheKey cacheKey)
      Returns a cached successful resolution result when present or rethrows a cached failure for the same key.
      Parameters:
      cacheKey - composite key identifying the query contract and DTO path
      Returns:
      cached successful resolution, or null when the key is not present
    • putSuccessfulResolution

      public void putSuccessfulResolution(@NonNull @NonNull CacheKey cacheKey, @NonNull @NonNull ResolutionResult result)
      Stores a successful DTO-aware path-resolution result.
      Parameters:
      cacheKey - composite key identifying the query contract and DTO path
      result - successful resolution result to cache
    • putFailedResolution

      public void putFailedResolution(@NonNull @NonNull CacheKey cacheKey, @NonNull @NonNull RuntimeException ex)
      Stores a failed DTO-aware path-resolution attempt.
      Parameters:
      cacheKey - composite key identifying the query contract and DTO path
      ex - exception raised while resolving the path
    • getKeyLock

      public Lock getKeyLock(@NonNull @NonNull CacheKey cacheKey)
      Returns the striped lock associated with the supplied cache key.

      The returned lock is selected by hashing the key into the configured stripe set so callers can coordinate cache population without allocating a dedicated lock per selector.

      Parameters:
      cacheKey - composite key identifying the query contract and DTO path
      Returns:
      lock guarding cache population for the key's stripe