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. When the failed-resolution cache is configured with a capacity of 0, failed entries are evicted immediately after insertion, effectively disabling failed-resolution caching while leaving successful-resolution caching enabled.

  • 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; a value of 0 causes failed entries to be evicted immediately after insertion, effectively disabling failed-resolution caching
      lockStripeCount - number of lock stripes used to coordinate cache population for selector keys; must be positive
      Throws:
      QueryConfigurationException - if cache initialization fails; this can occur when failedResolutionsMaxCapacity is negative, lockStripeCount is non-positive, or the underlying cache/lock infrastructure rejects the supplied configuration
  • 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
      Throws:
      RuntimeException - if a failed resolution was previously cached for the supplied key; the cached exception instance is rethrown
    • 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; the same exception instance will be rethrown by resolveFromCache(CacheKey) while it remains cached
    • 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