Class DTOAwareFieldResolutionCache
java.lang.Object
in.co.akshitbansal.springwebquery.resolver.field.cache.DTOAwareFieldResolutionCache
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 Summary
ConstructorsConstructorDescriptionDTOAwareFieldResolutionCache(int failedResolutionsMaxCapacity, int lockStripeCount) Creates the shared cache used by cached DTO-aware field resolvers. -
Method Summary
Modifier and TypeMethodDescriptiongetKeyLock(@NonNull CacheKey cacheKey) Returns the striped lock associated with the supplied cache key.voidputFailedResolution(@NonNull CacheKey cacheKey, @NonNull RuntimeException ex) Stores a failed DTO-aware path-resolution attempt.voidputSuccessfulResolution(@NonNull CacheKey cacheKey, @NonNull ResolutionResult result) Stores a successful DTO-aware path-resolution result.@Nullable ResolutionResultresolveFromCache(@NonNull CacheKey cacheKey) Returns a cached successful resolution result when present or rethrows a cached failure for the same key.
-
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 of0causes failed entries to be evicted immediately after insertion, effectively disabling failed-resolution cachinglockStripeCount- number of lock stripes used to coordinate cache population for selector keys; must be positive- Throws:
QueryConfigurationException- if cache initialization fails; this can occur whenfailedResolutionsMaxCapacityis negative,lockStripeCountis non-positive, or the underlying cache/lock infrastructure rejects the supplied configuration
-
-
Method Details
-
resolveFromCache
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
nullwhen 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 pathresult- 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 pathex- exception raised while resolving the path; the same exception instance will be rethrown byresolveFromCache(CacheKey)while it remains cached
-
getKeyLock
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
-