5
5
"time"
6
6
7
7
"github.com/m1k1o/go-transcode/internal/utils"
8
- "github.com/rs/zerolog/log"
9
8
)
10
9
11
10
func (m * ManagerCtx ) getFromCache (key string ) (* utils.Cache , bool ) {
@@ -15,7 +14,7 @@ func (m *ManagerCtx) getFromCache(key string) (*utils.Cache, bool) {
15
14
16
15
// on cache miss
17
16
if ! ok {
18
- log . Warn ().Str ("key" , key ).Msg ("cache miss" )
17
+ m . logger . Debug ().Str ("key" , key ).Msg ("cache miss" )
19
18
return nil , false
20
19
}
21
20
@@ -26,13 +25,11 @@ func (m *ManagerCtx) getFromCache(key string) (*utils.Cache, bool) {
26
25
}
27
26
28
27
// cache hit
29
- log . Info ().Str ("key" , key ).Msg ("cache hit !!!! " )
28
+ m . logger . Debug ().Str ("key" , key ).Msg ("cache hit" )
30
29
return entry , true
31
30
}
32
31
33
32
func (m * ManagerCtx ) saveToCache (key string , reader io.Reader , duration time.Duration ) * utils.Cache {
34
- log .Info ().Str ("key" , key ).Msg ("cache add ++++" )
35
-
36
33
m .cacheMu .Lock ()
37
34
cache := utils .NewCache (time .Now ().Add (duration ))
38
35
m .cache [key ] = cache
@@ -43,7 +40,9 @@ func (m *ManagerCtx) saveToCache(key string, reader io.Reader, duration time.Dur
43
40
defer cache .Close ()
44
41
45
42
_ , err := io .Copy (cache , reader )
46
- log .Err (err ).Msg ("copied to cache" )
43
+ if err != nil {
44
+ m .logger .Err (err ).Msg ("error while copying to cache" )
45
+ }
47
46
48
47
// close reader, if it needs to be closed
49
48
if closer , ok := reader .(io.ReadCloser ); ok {
@@ -59,7 +58,6 @@ func (m *ManagerCtx) removeFromCache(key string) {
59
58
defer m .cacheMu .Unlock ()
60
59
61
60
delete (m .cache , key )
62
- log .Info ().Str ("key" , key ).Msg ("cache remove ----" )
63
61
}
64
62
65
63
func (m * ManagerCtx ) clearCache () {
@@ -70,7 +68,7 @@ func (m *ManagerCtx) clearCache() {
70
68
for key , entry := range m .cache {
71
69
if time .Now ().After (entry .Expires ) {
72
70
delete (m .cache , key )
73
- log . Info ().Str ("key" , key ).Msg ("cache cleanup remove expired" )
71
+ m . logger . Debug ().Str ("key" , key ).Msg ("cache cleanup remove expired" )
74
72
}
75
73
}
76
74
}
0 commit comments