Skip to content

Commit ae7cf2a

Browse files
committed
chore: correct typos and improve comments in cache.go
1 parent 1b7f034 commit ae7cf2a

1 file changed

Lines changed: 21 additions & 23 deletions

File tree

cache.go

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var (
1414
ErrFullMemory = errors.New("cannot create new record: memory is full")
1515
)
1616

17-
// Constans below are used for shard section identification.
17+
// Constants below are used for shard section identification.
1818
const (
1919
// SMSH - Small Shards section
2020
SMSH = iota + 1
@@ -38,7 +38,7 @@ type AtomicCache struct {
3838
// Lookup structure used for global index.
3939
lookup map[string]LookupRecord
4040

41-
// Shards lookup tables which contains information about shards sections.
41+
// Shards lookup tables which contain information about shard sections.
4242
smallShards, mediumShards, largeShards ShardsLookup
4343

4444
// Size of byte array used for memory allocation at small shard section.
@@ -63,8 +63,8 @@ type AtomicCache struct {
6363
// Garbage collector counter for starter.
6464
GcCounter uint32
6565

66-
// Buffer contains all unattended cache set requests. It has a maximum site
67-
// which is equal to MaxRecords value.
66+
// Buffer contains all unattended cache set requests. It has a maximum size
67+
// which is equal to the MaxRecords value.
6868
buffer []BufferItem
6969
}
7070

@@ -79,25 +79,25 @@ type ShardsLookup struct {
7979
shardsAvail []int
8080
}
8181

82-
// LookupRecord represents item in lookup table. One record contains index of
83-
// shard and record. So we can determine which shard access and which record of
84-
// shard to get. Record also contains expiration time.
82+
// LookupRecord represents an item in the lookup table. One record contains the index of
83+
// the shard and record. So we can determine which shard to access and which record of
84+
// the shard to get. Record also contains expiration time.
8585
type LookupRecord struct {
8686
RecordIndex int
8787
ShardIndex int
8888
ShardSection int
8989
Expiration time.Time
9090
}
9191

92-
// BufferItem is used for buffer, which contains all unattended cache set
93-
// request.
92+
// BufferItem is used for the buffer, which contains all unattended cache set
93+
// requests.
9494
type BufferItem struct {
9595
Key string
9696
Data []byte
9797
Expire time.Duration
9898
}
9999

100-
// New initialize whole cache memory with one allocated shard.
100+
// New initializes the whole cache memory with one allocated shard.
101101
func New(opts ...Option) *AtomicCache {
102102
var options = &Options{
103103
RecordSizeSmall: 512,
@@ -138,8 +138,8 @@ func New(opts ...Option) *AtomicCache {
138138
return cache
139139
}
140140

141-
// initShardsSection provides shards sections initialization. So the cache has
142-
// one shard in each section at the begging.
141+
// initShardsSection provides shard section initialization. So the cache has
142+
// one shard in each section at the beginning.
143143
func initShardsSection(shardsSection *ShardsLookup, maxShards, maxRecords, recordSize int) {
144144
var shardIndex int
145145

@@ -153,10 +153,9 @@ func initShardsSection(shardsSection *ShardsLookup, maxShards, maxRecords, recor
153153
shardsSection.shards[shardIndex] = NewShard(maxRecords, recordSize)
154154
}
155155

156-
// Set store data to cache memory. If key/record is already in memory, then data
157-
// are replaced. If not, it checks if there are some allocated shard with empty
158-
// space for data. If there is no empty space, new shard is allocated. Otherwise
159-
// some valid record (FIFO queue) is deleted and new one is stored.
156+
// Set stores data to cache memory. If the key/record is already in memory, then data
157+
// are replaced. If not, it checks if there is an allocated shard with empty
158+
// space for data. If there is no empty space, a new shard is allocated.
160159
// Remarks:
161160
// - If expiration time is set to 0 then maximum expiration time is used (48 hours).
162161
// - If expiration time is KeepTTL, then current expiration time is preserved.
@@ -395,9 +394,9 @@ func (a *AtomicCache) getEmptyShard(shardSectionID int) (int, bool) {
395394
return shardIndex, true
396395
}
397396

398-
// getShardsSectionBySize returns shards section lookup structure and section
399-
// identifier as a second value. The function requires the data size value on
400-
// input. If data are bigger than allowed value, then nil and 0 is returned.
397+
// getShardsSectionBySize returns the shard section lookup structure and section
398+
// identifier as a second value. The function requires the data size value as input.
399+
// If data are bigger than the allowed value, then nil and 0 are returned.
401400
// This method is not thread safe and additional locks are required.
402401
func (a *AtomicCache) getShardsSectionBySize(dataSize int) (*ShardsLookup, int) {
403402
if dataSize <= int(a.RecordSizeSmall) {
@@ -454,10 +453,9 @@ func (a *AtomicCache) getExprTime(expire time.Duration) time.Time {
454453
return time.Now().Add(expire)
455454
}
456455

457-
// collectGarbage provides garbage collect. It goes throught lookup table and
458-
// checks expiration time. If shard end up empty, then garbage collect release
459-
// him, but only if there is more than one shard in charge (we always have one
460-
// active shard).
456+
// collectGarbage provides garbage collection. It goes through the lookup table and
457+
// checks expiration time. If a shard ends up empty, then garbage collection releases
458+
// it, but only if there is more than one shard in use (there is always at least one active shard).
461459
func (a *AtomicCache) collectGarbage() {
462460
a.Lock()
463461
for k, v := range a.lookup {

0 commit comments

Comments
 (0)