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.
-
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 retainlockStripeCount- 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
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
-
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
-
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
-