@@ -27,9 +27,7 @@ func NewT[K constraints.Ordered, V any](cache Cache) *T[K, V] {
2727// The expiration time of the cached value is determined by the cache configuration.
2828func (w * T [K , V ]) Set (ctx context.Context , key string , id K , v V ) error {
2929 c := w .Cache .(* jetCache )
30-
31- combKey := fmt .Sprintf ("%s%s%v" , key , c .separator , id )
32- return w .Cache .Set (ctx , combKey , Value (v ))
30+ return w .Cache .Set (ctx , w .combKey (c , key , id ), Value (v ))
3331}
3432
3533// Get retrieves the value associated with the given `key` and `id`.
@@ -44,8 +42,7 @@ func (w *T[K, V]) Get(ctx context.Context, key string, id K, fn func(context.Con
4442 c := w .Cache .(* jetCache )
4543
4644 var varT V
47- combKey := fmt .Sprintf ("%s%s%v" , key , c .separator , id )
48- err := w .Once (ctx , combKey , Value (& varT ), Do (func (ctx context.Context ) (any , error ) {
45+ err := w .Once (ctx , w .combKey (c , key , id ), Value (& varT ), Do (func (ctx context.Context ) (any , error ) {
4946 return fn (ctx , id )
5047 }))
5148
@@ -78,8 +75,7 @@ func (w *T[K, V]) MGetWithErr(ctx context.Context, key string, ids []K, fn func(
7875
7976 miss := make (map [string ]K , len (ids ))
8077 for _ , missId := range ids {
81- missKey := fmt .Sprintf ("%s%s%v" , key , c .separator , missId )
82- miss [missKey ] = missId
78+ miss [w .combKey (c , key , missId )] = missId
8379 }
8480
8581 if c .local != nil {
@@ -279,3 +275,19 @@ func (w *T[K, V]) mQueryAndSetCache(ctx context.Context, miss map[string]K, fn f
279275
280276 return
281277}
278+
279+ // Delete deletes cached val with the given `key` and `id`.
280+ func (w * T [K , V ]) Delete (ctx context.Context , key string , id K ) error {
281+ c := w .Cache .(* jetCache )
282+ return c .Delete (ctx , w .combKey (c , key , id ))
283+ }
284+
285+ // Exists reports whether val for the given `key` and `id` exists.
286+ func (w * T [K , V ]) Exists (ctx context.Context , key string , id K ) bool {
287+ c := w .Cache .(* jetCache )
288+ return c .Exists (ctx , w .combKey (c , key , id ))
289+ }
290+
291+ func (w * T [K , V ]) combKey (c * jetCache , key string , id K ) string {
292+ return fmt .Sprintf ("%s%s%v" , key , c .separator , id )
293+ }
0 commit comments