Simplify cache name snapshot creation by codingkiddo · Pull Request #1955 · ben-manes/caffeine (original) (raw)
Summary
This PR simplifies CacheManagerImpl#getCacheNames() by replacing the existing ArrayList + Collections.unmodifiableCollection(...) usage with List.copyOf(...).
Motivation
The current implementation creates a snapshot of the cache names and wraps it as an unmodifiable collection:
Collections.unmodifiableCollection(new ArrayList<>(caches.keySet()))
List.copyOf(...) provides the same intent more directly by creating an unmodifiable snapshot of the given collection.
Changes
return List.copyOf(caches.keySet());
This reduces boilerplate and improves readability without changing the method signature or intended behavior.
Notes
- No public API behavior is changed.
- The method signature remains
Collection<String>to preserve public binary compatibility. - The returned collection remains unmodifiable.
- The cache names are still returned as a snapshot.
- This change is limited to JCache cache-name snapshot creation.
- No core cache eviction or performance-sensitive logic is changed.
Validation
./gradlew :jcache:test./gradlew assemble