Skip to content

Commit cab0921

Browse files
committed
cache fix logs.
1 parent 0c711fa commit cab0921

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

hlsproxy/cache.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"time"
66

77
"github.com/m1k1o/go-transcode/internal/utils"
8-
"github.com/rs/zerolog/log"
98
)
109

1110
func (m *ManagerCtx) getFromCache(key string) (*utils.Cache, bool) {
@@ -15,7 +14,7 @@ func (m *ManagerCtx) getFromCache(key string) (*utils.Cache, bool) {
1514

1615
// on cache miss
1716
if !ok {
18-
log.Warn().Str("key", key).Msg("cache miss")
17+
m.logger.Debug().Str("key", key).Msg("cache miss")
1918
return nil, false
2019
}
2120

@@ -26,13 +25,11 @@ func (m *ManagerCtx) getFromCache(key string) (*utils.Cache, bool) {
2625
}
2726

2827
// cache hit
29-
log.Info().Str("key", key).Msg("cache hit !!!!")
28+
m.logger.Debug().Str("key", key).Msg("cache hit")
3029
return entry, true
3130
}
3231

3332
func (m *ManagerCtx) saveToCache(key string, reader io.Reader, duration time.Duration) *utils.Cache {
34-
log.Info().Str("key", key).Msg("cache add ++++")
35-
3633
m.cacheMu.Lock()
3734
cache := utils.NewCache(time.Now().Add(duration))
3835
m.cache[key] = cache
@@ -43,7 +40,9 @@ func (m *ManagerCtx) saveToCache(key string, reader io.Reader, duration time.Dur
4340
defer cache.Close()
4441

4542
_, 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+
}
4746

4847
// close reader, if it needs to be closed
4948
if closer, ok := reader.(io.ReadCloser); ok {
@@ -59,7 +58,6 @@ func (m *ManagerCtx) removeFromCache(key string) {
5958
defer m.cacheMu.Unlock()
6059

6160
delete(m.cache, key)
62-
log.Info().Str("key", key).Msg("cache remove ----")
6361
}
6462

6563
func (m *ManagerCtx) clearCache() {
@@ -70,7 +68,7 @@ func (m *ManagerCtx) clearCache() {
7068
for key, entry := range m.cache {
7169
if time.Now().After(entry.Expires) {
7270
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")
7472
}
7573
}
7674
}

0 commit comments

Comments
 (0)