@@ -2,7 +2,7 @@ package zio.cache
2
2
3
3
import zio .internal .MutableConcurrentQueue
4
4
import zio .stacktracer .TracingImplicits .disableAutoTrace
5
- import zio .{Exit , IO , Promise , UIO , URIO , ZIO , ZTraceElement }
5
+ import zio .{Exit , IO , Promise , Trace , UIO , URIO , ZIO }
6
6
7
7
import java .time .{Duration , Instant }
8
8
import java .util .Map
@@ -31,25 +31,25 @@ sealed abstract class Cache[-Key, +Error, +Value] {
31
31
/**
32
32
* Returns statistics for this cache.
33
33
*/
34
- def cacheStats (implicit trace : ZTraceElement ): UIO [CacheStats ]
34
+ def cacheStats (implicit trace : Trace ): UIO [CacheStats ]
35
35
36
36
/**
37
37
* Returns whether a value associated with the specified key exists in the
38
38
* cache.
39
39
*/
40
- def contains (key : Key )(implicit trace : ZTraceElement ): UIO [Boolean ]
40
+ def contains (key : Key )(implicit trace : Trace ): UIO [Boolean ]
41
41
42
42
/**
43
43
* Returns statistics for the specified entry.
44
44
*/
45
- def entryStats (key : Key )(implicit trace : ZTraceElement ): UIO [Option [EntryStats ]]
45
+ def entryStats (key : Key )(implicit trace : Trace ): UIO [Option [EntryStats ]]
46
46
47
47
/**
48
48
* Retrieves the value associated with the specified key if it exists.
49
49
* Otherwise computes the value with the lookup function, puts it in the
50
50
* cache, and returns it.
51
51
*/
52
- def get (key : Key )(implicit trace : ZTraceElement ): IO [Error , Value ]
52
+ def get (key : Key )(implicit trace : Trace ): IO [Error , Value ]
53
53
54
54
/**
55
55
* Computes the value associated with the specified key, with the lookup
@@ -65,7 +65,7 @@ sealed abstract class Cache[-Key, +Error, +Value] {
65
65
/**
66
66
* Invalidates the value associated with the specified key.
67
67
*/
68
- def invalidate (key : Key )(implicit trace : ZTraceElement ): UIO [Unit ]
68
+ def invalidate (key : Key )(implicit trace : Trace ): UIO [Unit ]
69
69
70
70
/**
71
71
* Invalidates all values in the cache.
@@ -75,7 +75,7 @@ sealed abstract class Cache[-Key, +Error, +Value] {
75
75
/**
76
76
* Returns the approximate number of values in the cache.
77
77
*/
78
- def size (implicit trace : ZTraceElement ): UIO [Int ]
78
+ def size (implicit trace : Trace ): UIO [Int ]
79
79
}
80
80
81
81
object Cache {
@@ -88,7 +88,7 @@ object Cache {
88
88
capacity : Int ,
89
89
timeToLive : Duration ,
90
90
lookup : Lookup [Key , Environment , Error , Value ]
91
- )(implicit trace : ZTraceElement ): URIO [Environment , Cache [Key , Error , Value ]] =
91
+ )(implicit trace : Trace ): URIO [Environment , Cache [Key , Error , Value ]] =
92
92
makeWith(capacity, lookup)(_ => timeToLive)
93
93
94
94
/**
@@ -101,7 +101,7 @@ object Cache {
101
101
lookup : Lookup [Key , Environment , Error , Value ]
102
102
)(
103
103
timeToLive : Exit [Error , Value ] => Duration
104
- )(implicit trace : ZTraceElement ): URIO [Environment , Cache [Key , Error , Value ]] =
104
+ )(implicit trace : Trace ): URIO [Environment , Cache [Key , Error , Value ]] =
105
105
ZIO .clock.flatMap { clock =>
106
106
ZIO .environment[Environment ].flatMap { environment =>
107
107
ZIO .fiberId.map { fiberId =>
@@ -145,13 +145,13 @@ object Cache {
145
145
146
146
new Cache [Key , Error , Value ] {
147
147
148
- override def cacheStats (implicit trace : ZTraceElement ): UIO [CacheStats ] =
148
+ override def cacheStats (implicit trace : Trace ): UIO [CacheStats ] =
149
149
ZIO .succeed(CacheStats (hits.longValue, misses.longValue, map.size))
150
150
151
- override def contains (k : Key )(implicit trace : ZTraceElement ): UIO [Boolean ] =
151
+ override def contains (k : Key )(implicit trace : Trace ): UIO [Boolean ] =
152
152
ZIO .succeed(map.containsKey(k))
153
153
154
- override def entryStats (k : Key )(implicit trace : ZTraceElement ): UIO [Option [EntryStats ]] =
154
+ override def entryStats (k : Key )(implicit trace : Trace ): UIO [Option [EntryStats ]] =
155
155
ZIO .succeed {
156
156
val value = map.get(k)
157
157
if (value eq null ) None
@@ -167,7 +167,7 @@ object Cache {
167
167
}
168
168
}
169
169
170
- override def get (k : Key )(implicit trace : ZTraceElement ): IO [Error , Value ] =
170
+ override def get (k : Key )(implicit trace : Trace ): IO [Error , Value ] =
171
171
ZIO .suspendSucceed {
172
172
var key : MapKey [Key ] = null
173
173
var promise : Promise [Error , Value ] = null
@@ -241,7 +241,7 @@ object Cache {
241
241
result.unit
242
242
}
243
243
244
- override def invalidate (k : Key )(implicit trace : ZTraceElement ): UIO [Unit ] =
244
+ override def invalidate (k : Key )(implicit trace : Trace ): UIO [Unit ] =
245
245
ZIO .succeed {
246
246
map.remove(k)
247
247
()
@@ -252,7 +252,7 @@ object Cache {
252
252
map.clear()
253
253
}
254
254
255
- def size (implicit trace : ZTraceElement ): UIO [Int ] =
255
+ def size (implicit trace : Trace ): UIO [Int ] =
256
256
ZIO .succeed(map.size)
257
257
258
258
private def lookupValueOf (key : Key , promise : Promise [Error , Value ]): IO [Error , Value ] =
0 commit comments