Skip to content

Commit cfe0f2a

Browse files
cache/mongo: add stopGC function for MongoCache
1 parent b4291b8 commit cfe0f2a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

mongo_cache.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ import (
77
mgo "gopkg.in/mgo.v2"
88
)
99

10-
// MongoCache ...
10+
// MongoCache holds the cache values that will be stored in mongoDB
1111
type MongoCache struct {
1212
mongeSession *mgo.Session
1313
// cache holds the cache data
14-
// cache *KeyValue
1514

1615
CollectionName string
1716
// ttl is a duration for a cache key to expire
@@ -89,6 +88,7 @@ func (m *MongoCache) set(key string, value interface{}) error {
8988
return m.CreateKeyValueWithExpiration(kv)
9089
}
9190

91+
// StartGCol starts the garbage collector with given time interval
9292
func (m *MongoCache) StartGCol(gcInterval time.Duration) {
9393
if gcInterval <= 0 {
9494
return
@@ -115,3 +115,15 @@ func (m *MongoCache) StartGCol(gcInterval time.Duration) {
115115
}
116116
}()
117117
}
118+
119+
// StopGC stops sweeping goroutine.
120+
func (r *MemoryTTL) StopGCol() {
121+
if r.gcTicker != nil {
122+
r.Lock()
123+
r.gcTicker.Stop()
124+
r.gcTicker = nil
125+
close(r.done)
126+
r.done = nil
127+
r.Unlock()
128+
}
129+
}

0 commit comments

Comments
 (0)