Skip to content

Commit 29ef714

Browse files
committed
Changed cache function visibility
1 parent 3fd3b98 commit 29ef714

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

cache.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,21 @@ type portsCache struct {
4444
deletionCallback func(port *discovery.Port)
4545
}
4646

47-
// NewCache creates a new portsCache and returns it.
47+
// newCache creates a new portsCache and returns it.
4848
// itemsTTL is the TTL of a single item, when it's reached
4949
// the stored item is deleted.
50-
func NewCache(itemsTTL time.Duration) *portsCache {
50+
func newCache(itemsTTL time.Duration) *portsCache {
5151
return &portsCache{
5252
itemsTTL: itemsTTL,
5353
data: make(map[string]*cacheItem),
5454
}
5555
}
5656

57-
// Set stores a new port and sets its TTL.
57+
// set stores a new port and sets its TTL.
5858
// If the specified key is already found the item's TTL is
5959
// renewed.
60-
// Set is thread safe.
61-
func (c *portsCache) Set(key string, port *discovery.Port) {
60+
// set is thread safe.
61+
func (c *portsCache) set(key string, port *discovery.Port) {
6262
c.dataMutex.Lock()
6363
defer c.dataMutex.Unlock()
6464
// We need a cancellable context to avoid leaving
@@ -105,10 +105,10 @@ func (c *portsCache) Set(key string, port *discovery.Port) {
105105
}(key, item)
106106
}
107107

108-
// Get returns the item stored with the specified key and true.
108+
// get returns the item stored with the specified key and true.
109109
// If the item is not found returns a nil port and false.
110-
// Get is thread safe.
111-
func (c *portsCache) Get(key string) (*discovery.Port, bool) {
110+
// get is thread safe.
111+
func (c *portsCache) get(key string) (*discovery.Port, bool) {
112112
c.dataMutex.Lock()
113113
defer c.dataMutex.Unlock()
114114
if item, ok := c.data[key]; ok {
@@ -117,9 +117,9 @@ func (c *portsCache) Get(key string) (*discovery.Port, bool) {
117117
return nil, false
118118
}
119119

120-
// Clear removes all the stored items and stops their TTL timers.
121-
// Clear is thread safe.
122-
func (c *portsCache) Clear() {
120+
// clear removes all the stored items and stops their TTL timers.
121+
// clear is thread safe.
122+
func (c *portsCache) clear() {
123123
c.dataMutex.Lock()
124124
defer c.dataMutex.Unlock()
125125
for key, item := range c.data {

main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type MDNSDiscovery struct {
6363
func (d *MDNSDiscovery) Hello(userAgent string, protocolVersion int) error {
6464
// The mdns library used has some logs statement that we must disable
6565
log.SetOutput(ioutil.Discard)
66-
d.portsCache = NewCache(portsTTL)
66+
d.portsCache = newCache(portsTTL)
6767
return nil
6868
}
6969

@@ -78,7 +78,7 @@ func (d *MDNSDiscovery) Stop() error {
7878
d.entriesChan = nil
7979
}
8080
if d.portsCache != nil {
81-
d.portsCache.Clear()
81+
d.portsCache.clear()
8282
}
8383
return nil
8484
}
@@ -107,11 +107,11 @@ func (d *MDNSDiscovery) StartSync(eventCB discovery.EventCallback, errorCB disco
107107
for entry := range d.entriesChan {
108108
port := toDiscoveryPort(entry)
109109
key := portKey(port)
110-
if _, ok := d.portsCache.Get(key); !ok {
110+
if _, ok := d.portsCache.get(key); !ok {
111111
// Port is not cached so let the user know a new one has been found
112112
eventCB("add", port)
113113
}
114-
d.portsCache.Set(portKey(port), port)
114+
d.portsCache.set(portKey(port), port)
115115
}
116116
}()
117117

0 commit comments

Comments
 (0)