@@ -86,7 +86,7 @@ type baseClient[K comparable, V any] struct {
86
86
mutex * sync.RWMutex
87
87
nearCache * localCacheImpl [K , V ]
88
88
nearCacheListener * namedCacheNearCacheListener [K , V ]
89
- nearCacheLifecycleListener * namedCacheNearLifecyleListener [K , V ]
89
+ nearCacheLifecycleListener * namedCacheNearLifestyleListener [K , V ]
90
90
91
91
// gRPC v1 listeners registered
92
92
keyListenersV1 map [K ]* listenerGroupV1 [K , V ]
@@ -103,15 +103,26 @@ type CacheOptions struct {
103
103
104
104
// NearCacheOptions defines options when creating a near cache.
105
105
type NearCacheOptions struct {
106
- TTL time.Duration
107
- HighUnits int64
108
- HighUnitsMemory int64
106
+ // TTL is the maximum time to keep the entry in the near cache. When this time has been reached it will be expired.
107
+ TTL time.Duration
108
+
109
+ // HighUnits is the maximum number of cache entries to keep in the near cache.
110
+ HighUnits int64
111
+
112
+ // HighUnitsMemory is the maximum amount of memory to use for entries in the near cache.
113
+ HighUnitsMemory int64
114
+
109
115
InvalidationStrategy InvalidationStrategyType // currently only supports ListenAll
116
+
117
+ // PruneFactor indicates the percentage of the total number of units that will remain
118
+ // after the cache manager prunes the near cache(i.e. this is the "low watermark" value)
119
+ // this value is in the range 0.1 to 1.0 and the default is 0.8 or 80%.
120
+ PruneFactor float32
110
121
}
111
122
112
123
func (n NearCacheOptions ) String () string {
113
- return fmt .Sprintf ("NearCacheOptions{TTL=%v, HighUnits=%v, HighUnitsMemory=%v, invalidationStrategy=%v}" ,
114
- n .TTL , n .HighUnits , n .HighUnitsMemory , getInvalidationStrategyString (n .InvalidationStrategy ))
124
+ return fmt .Sprintf ("NearCacheOptions{TTL=%v, HighUnits=%v, HighUnitsMemory=%v, PruneFactor=%.2f, invalidationStrategy=%v}" ,
125
+ n .TTL , n .HighUnits , n .HighUnitsMemory , n . PruneFactor , getInvalidationStrategyString (n .InvalidationStrategy ))
115
126
}
116
127
117
128
// WithExpiry returns a function to set the default expiry for a [NamedCache]. This option is not valid on [NamedMap].
@@ -134,6 +145,7 @@ func executeClear[K comparable, V any](ctx context.Context, bc *baseClient[K, V]
134
145
err = bc .ensureClientConnection ()
135
146
nearCache = bc .nearCache
136
147
)
148
+
137
149
if err != nil {
138
150
return err
139
151
}
@@ -152,7 +164,7 @@ func executeClear[K comparable, V any](ctx context.Context, bc *baseClient[K, V]
152
164
}
153
165
154
166
// clear the near cache
155
- if nearCache != nil {
167
+ if bc . session . GetProtocolVersion () == 0 && nearCache != nil {
156
168
nearCache .Clear ()
157
169
}
158
170
@@ -272,7 +284,7 @@ func executeTruncate[K comparable, V any](ctx context.Context, bc *baseClient[K,
272
284
_ , err = bc .client .Truncate (newCtx , & request )
273
285
}
274
286
275
- // clear the near cache
287
+ // clear the near cache as the lifecycle listeners are not synchronous
276
288
if nearCache != nil {
277
289
nearCache .Clear ()
278
290
}
@@ -1396,8 +1408,8 @@ func executePutAll[K comparable, V any](ctx context.Context, bc *baseClient[K, V
1396
1408
}
1397
1409
}
1398
1410
1399
- // if we have near cache and the entry exists then update
1400
- if nearCache != nil {
1411
+ // if we have near cache and the entry exists then update (gRPC v0)
1412
+ if bc . session . GetProtocolVersion () == 0 && nearCache != nil {
1401
1413
for k , v := range entries {
1402
1414
if oldVal := nearCache .Get (k ); oldVal != nil {
1403
1415
nearCache .Put (k , v )
@@ -1510,8 +1522,8 @@ func executePutWithExpiry[K comparable, V any](ctx context.Context, bc *baseClie
1510
1522
}
1511
1523
1512
1524
// if we have near cache and the entry exists then update this as well because we do
1513
- // not use synchronous listener like we do on Java
1514
- if nearCache != nil {
1525
+ // not use synchronous listener in gRPC v0
1526
+ if bc . session . GetProtocolVersion () == 0 && nearCache != nil {
1515
1527
if oldValue := nearCache .Get (key ); oldValue != nil {
1516
1528
nearCache .Put (key , value )
1517
1529
}
@@ -1580,7 +1592,7 @@ func executeRemove[K comparable, V any](ctx context.Context, bc *baseClient[K, V
1580
1592
}
1581
1593
}
1582
1594
1583
- if nearCache != nil {
1595
+ if bc . session . GetProtocolVersion () == 0 && nearCache != nil {
1584
1596
nearCache .Remove (key )
1585
1597
}
1586
1598
@@ -1632,7 +1644,7 @@ func executeRemoveMapping[K comparable, V any](ctx context.Context, bc *baseClie
1632
1644
}
1633
1645
}
1634
1646
1635
- if result .Value && nearCache != nil {
1647
+ if bc . session . GetProtocolVersion () == 0 && result .Value && nearCache != nil {
1636
1648
nearCache .Remove (key )
1637
1649
}
1638
1650
@@ -1738,7 +1750,7 @@ func executeReplaceMapping[K comparable, V any](ctx context.Context, bc *baseCli
1738
1750
}
1739
1751
}
1740
1752
1741
- if nearCache != nil && result .Value {
1753
+ if bc . session . GetProtocolVersion () == 0 && nearCache != nil && result .Value {
1742
1754
if old := nearCache .Get (key ); old != nil {
1743
1755
nearCache .Put (key , newValue )
1744
1756
}
0 commit comments