@@ -76,8 +76,8 @@ func TestExpireAfterWrite(t *testing.T) {
7676 type V int
7777
7878 matrixTest [K , V ](t , matrixTestOptions [K , V ]{
79- cacheOptions : loadingcache.CacheOptions [K , V ]{
80- ExpireAfterWrite : time .Minute ,
79+ cacheOptions : [] loadingcache.CacheOption [K , V ]{
80+ loadingcache. WithExpireAfterWrite [ K , V ]( time .Minute ) ,
8181 },
8282 },
8383 func (t * testing.T , ctx context.Context , cache loadingcache.Cache [K , V ]) {
@@ -108,8 +108,8 @@ func TestExpireAfterRead(t *testing.T) {
108108 type V int
109109
110110 matrixTest (t , matrixTestOptions [K , V ]{
111- cacheOptions : loadingcache.CacheOptions [K , V ]{
112- ExpireAfterRead : time .Minute ,
111+ cacheOptions : [] loadingcache.CacheOption [K , V ]{
112+ loadingcache. WithExpireAfterRead [ K , V ]( time .Minute ) ,
113113 },
114114 },
115115 func (t * testing.T , ctx context.Context , cache loadingcache.Cache [K , V ]) {
@@ -150,8 +150,8 @@ func TestLoadFunc(t *testing.T) {
150150
151151 loadFunc := & testLoadFunc [K , V ]{}
152152 matrixTest (t , matrixTestOptions [K , V ]{
153- cacheOptions : loadingcache.CacheOptions [K , V ]{
154- Load : loadFunc .LoadFunc ,
153+ cacheOptions : [] loadingcache.CacheOption [K , V ]{
154+ loadingcache . WithLoadFunc ( loadFunc .LoadFunc ) ,
155155 },
156156 },
157157 func (t * testing.T , _ context.Context , cache loadingcache.Cache [K , V ]) {
@@ -190,14 +190,14 @@ func TestMaxSize(t *testing.T) {
190190 type V int
191191 // TODO MaxSize is currently not properly enforced in a sharded environment
192192 caches := []loadingcache.Cache [K , V ]{
193- loadingcache .New (loadingcache. CacheOptions [ K , V ]{
194- MaxSize : 1 ,
195- } ),
196- loadingcache .New (loadingcache. CacheOptions [ K , V ]{
197- MaxSize : 1 ,
198- ShardCount : 3 ,
199- HashCodeFunc : stringHashCodeFunc [K ](),
200- } ),
193+ loadingcache .New (
194+ loadingcache. WithMaxSize [ K , V ]( 1 ) ,
195+ ),
196+ loadingcache .New (
197+ loadingcache. WithMaxSize [ K , V ]( 1 ) ,
198+ loadingcache. WithShardCount [ K , V ]( 3 ) ,
199+ loadingcache. WithHashCodeFunc [ K , V ]( stringHashCodeFunc [K ]() ),
200+ ),
201201 }
202202 for _ , cache := range caches {
203203 // With a capacity of one element, adding a second element
@@ -223,11 +223,14 @@ func TestRemovalListeners(t *testing.T) {
223223 removalListener := & testRemovalListener [K , V ]{}
224224 removalListener2 := & testRemovalListener [K , V ]{}
225225 matrixTest (t , matrixTestOptions [K , V ]{
226- cacheOptions : loadingcache.CacheOptions [K , V ]{
227- ExpireAfterRead : time .Minute ,
228- ExpireAfterWrite : 2 * time .Minute ,
229- MaxSize : 1 ,
230- RemovalListeners : []loadingcache.RemovalListener [K , V ]{removalListener .Listener , removalListener2 .Listener },
226+ cacheOptions : []loadingcache.CacheOption [K , V ]{
227+ loadingcache.WithExpireAfterRead [K , V ](time .Minute ),
228+ loadingcache.WithExpireAfterWrite [K , V ](2 * time .Minute ),
229+ loadingcache.WithMaxSize [K , V ](1 ),
230+ loadingcache .WithRemovalListeners (
231+ removalListener .Listener ,
232+ removalListener2 .Listener ,
233+ ),
231234 },
232235 },
233236 func (t * testing.T , ctx context.Context , cache loadingcache.Cache [K , V ]) {
@@ -295,14 +298,16 @@ func TestBackgroudEvict(t *testing.T) {
295298
296299 var removalWg sync.WaitGroup
297300 matrixTest (t , matrixTestOptions [K , V ]{
298- cacheOptions : loadingcache.CacheOptions [K , V ]{
299- ExpireAfterWrite : 20 * time .Second ,
300- BackgroundEvictFrequency : 10 * time .Second ,
301- RemovalListeners : []loadingcache.RemovalListener [K , V ]{func (notification loadingcache.RemovalNotification [K , V ]) {
302- if notification .Reason == loadingcache .RemovalReasonExpired {
303- removalWg .Done ()
304- }
305- }},
301+ cacheOptions : []loadingcache.CacheOption [K , V ]{
302+ loadingcache.WithExpireAfterWrite [K , V ](20 * time .Second ),
303+ loadingcache.WithBackgroundEvictFrequency [K , V ](10 * time .Second ),
304+ loadingcache .WithRemovalListeners (
305+ func (notification loadingcache.RemovalNotification [K , V ]) {
306+ if notification .Reason == loadingcache .RemovalReasonExpired {
307+ removalWg .Done ()
308+ }
309+ },
310+ ),
306311 },
307312 },
308313 func (t * testing.T , ctx context.Context , cache loadingcache.Cache [K , V ]) {
@@ -336,11 +341,11 @@ func TestTombstone(t *testing.T) {
336341 type V string
337342
338343 matrixTest (t , matrixTestOptions [K , V ]{
339- cacheOptions : loadingcache.CacheOptions [K , V ]{
340- Load : func (ctx context.Context , k K ) (V , error ) {
344+ cacheOptions : [] loadingcache.CacheOption [K , V ]{
345+ loadingcache . WithLoadFunc ( func (ctx context.Context , k K ) (V , error ) {
341346 var Nil V
342347 return Nil , loadingcache .Errorf (30 * time .Second , "testing error lol!" )
343- },
348+ }) ,
344349 },
345350 },
346351 func (t * testing.T , ctx context.Context , cache loadingcache.Cache [K , V ]) {
0 commit comments