-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Add comprehensive cache statistics to DefaultRequestCache #2516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Add CacheStatistics interface with detailed metrics tracking - Implement DefaultCacheStatistics with thread-safe counters - Add StatisticsCachingSupplier for hit/miss tracking per request - Update RequestCache interface to expose getStatistics() method - Track statistics by request type and cache retention policy - Support cache size monitoring and exception counting - Add comprehensive test coverage for all statistics features Features: - Overall metrics: total requests, hits, misses, hit/miss ratios - Per-request-type breakdown with individual hit ratios - Per-retention-policy statistics (SESSION_SCOPED, PERSISTENT, etc.) - Current cache sizes for each retention level - Cached exception tracking - Statistics reset functionality - Thread-safe implementation with atomic counters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels overly complex. Chances are we aren't going to need this level of abstraction and generality. I suggest starting with the simplest and most concrete thing that could work and expanding that if and when we need to.
* | ||
* @since 4.0.0 | ||
*/ | ||
@Experimental |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of experimental, can this just all move into the impl package and be made package private?
/** | ||
* Returns the total number of cache requests made. | ||
* | ||
* @return Total number of requests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
total
/** | ||
* Returns the number of cache hits (requests served from cache). | ||
* | ||
* @return Number of cache hits |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
number
/** | ||
* Returns the number of cache misses (requests that required computation). | ||
* | ||
* @return Number of cache misses |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in general first letter of a javadoc tag is not capitalized, per Oracle conventions
* @since 4.0.0 | ||
*/ | ||
@Experimental | ||
public interface CacheStatistics { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need an interface at all? There's only one implementation.
* Default implementation of cache statistics that tracks detailed metrics | ||
* about cache performance and usage patterns. | ||
*/ | ||
public class DefaultCacheStatistics implements CacheStatistics { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Combine CacheStatistics and DefaultCacheStatistics.
} | ||
|
||
@Override | ||
public void reset() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mutable objects are risky. Could you just use a new object instead?
I'll keep it in the impl instead. |
Summary
Adds comprehensive cache statistics tracking to the
DefaultRequestCache
implementation, providing detailed insights into cache performance and usage patterns.Features
Core Statistics
Detailed Breakdowns
Thread Safety
AtomicLong
for thread-safe operationsImplementation Details
New Classes
CacheStatistics
interface: Comprehensive API for accessing cache metricsDefaultCacheStatistics
: Thread-safe implementation with atomic countersStatisticsCachingSupplier
: Enhanced caching supplier that tracks hit/miss statisticsEnhanced Classes
RequestCache
interface: AddedgetStatistics()
methodDefaultRequestCache
: Integrated statistics tracking with minimal overheadAPI Design
Benefits
Performance Monitoring
Debugging & Troubleshooting
Production Monitoring
Testing
CacheStatisticsTest
covers all statistics functionalityUsage Examples
Basic Statistics
Request Type Analysis
Cache Size Monitoring
Impact
This enhancement provides valuable insights into Maven's caching behavior without affecting existing functionality or performance.
Pull Request opened by Augment Code with guidance from the PR author