@@ -57,13 +57,30 @@ public class RequestCacheStats implements Writeable, ToXContentFragment {
5757
5858 public RequestCacheStats () {}
5959
60+ /**
61+ * Private constructor that takes a builder.
62+ * This is the sole entry point for creating a new RequestCacheStats object.
63+ * @param builder The builder instance containing all the values.
64+ */
65+ private RequestCacheStats (Builder builder ) {
66+ this .memorySize = builder .memorySize ;
67+ this .evictions = builder .evictions ;
68+ this .hitCount = builder .hitCount ;
69+ this .missCount = builder .missCount ;
70+ }
71+
6072 public RequestCacheStats (StreamInput in ) throws IOException {
6173 memorySize = in .readVLong ();
6274 evictions = in .readVLong ();
6375 hitCount = in .readVLong ();
6476 missCount = in .readVLong ();
6577 }
6678
79+ /**
80+ * This constructor will be deprecated starting in version 3.4.0.
81+ * Use {@link Builder} instead.
82+ */
83+ @ Deprecated
6784 public RequestCacheStats (long memorySize , long evictions , long hitCount , long missCount ) {
6885 this .memorySize = memorySize ;
6986 this .evictions = evictions ;
@@ -98,6 +115,48 @@ public long getMissCount() {
98115 return this .missCount ;
99116 }
100117
118+ /**
119+ * Builder for the {@link RequestCacheStats} class.
120+ * Provides a fluent API for constructing a RequestCacheStats object.
121+ */
122+ public static class Builder {
123+ private long memorySize = 0 ;
124+ private long evictions = 0 ;
125+ private long hitCount = 0 ;
126+ private long missCount = 0 ;
127+
128+ public Builder () {}
129+
130+ public Builder memorySize (long count ) {
131+ this .memorySize = count ;
132+ return this ;
133+ }
134+
135+ public Builder evictions (long count ) {
136+ this .evictions = count ;
137+ return this ;
138+ }
139+
140+ public Builder hitCount (long count ) {
141+ this .hitCount = count ;
142+ return this ;
143+ }
144+
145+ public Builder missCount (long count ) {
146+ this .missCount = count ;
147+ return this ;
148+ }
149+
150+ /**
151+ * Creates a {@link RequestCacheStats} object from the builder's current state.
152+ * @return A new RequestCacheStats instance.
153+ */
154+ public RequestCacheStats build () {
155+ return new RequestCacheStats (this );
156+ }
157+
158+ }
159+
101160 @ Override
102161 public void writeTo (StreamOutput out ) throws IOException {
103162 out .writeVLong (memorySize );
0 commit comments