diff --git a/background.go b/background.go index 49189a1..a5911c2 100644 --- a/background.go +++ b/background.go @@ -36,10 +36,10 @@ func (km *keyMutex) Lock(key string) bool { } func (m CacheMap) BackgroundUpdate(key string, updater func() (interface{}, error)) { - //Lock the key from writes + // Lock the key from writes locked := backgroundMutex.Lock(key) if locked { - //Defer release write lock + // Defer release write lock defer backgroundMutex.Unlock(key) value, err := updater() if err == nil { diff --git a/cache_test.go b/cache_test.go index dcbe9f2..4a73260 100644 --- a/cache_test.go +++ b/cache_test.go @@ -23,28 +23,28 @@ func TestGet(t *testing.T) { t.Errorf("Expected cache to return `world` for `hello`") } - //Check to see if cleanup is clearing unexpired items + // Check to see if cleanup is clearing unexpired items time.Sleep(time.Millisecond * 200) data, exists = cache.Get("hello") if !exists || data == nil { t.Errorf("Expected cache to return data") } - //Check Cache is re-touching after a get + // Check Cache is re-touching after a get time.Sleep(time.Millisecond * 200) data, exists = cache.Get("hello") if !exists || data == nil { t.Errorf("Expected cache to return data") } - //Check Cache is optionally re-touching after a get + // Check Cache is optionally re-touching after a get time.Sleep(time.Millisecond * 200) data, exists = cache.TouchGet("hello", false) if !exists || data == nil { t.Errorf("Expected cache to return data") } - //Make sure cache clears after expiry + // Make sure cache clears after expiry time.Sleep(time.Millisecond * 200) data, exists = cache.Get("hello") if exists || data != nil { @@ -69,7 +69,7 @@ func TestMaxLifetime(t *testing.T) { t.Errorf("Expected cache to return `world` for `hello`") } - //Check to see if max lifetime has killed the item + // Check to see if max lifetime has killed the item time.Sleep(time.Millisecond * 200) data, exists = cache.Get("hello") if exists || data != nil { diff --git a/cleanup.go b/cleanup.go index 16e2cc9..7104383 100644 --- a/cleanup.go +++ b/cleanup.go @@ -14,7 +14,7 @@ func (ms *CacheMapShared) Flush() { ms.Unlock() } -//Cleanup removes any expired items from the cache map +// Cleanup removes any expired items from the cache map func (ms *CacheMapShared) Cleanup() { ms.Lock() for key, item := range ms.items { diff --git a/item.go b/item.go index fd5e6ac..85c3ca3 100644 --- a/item.go +++ b/item.go @@ -25,7 +25,7 @@ func newItem(value interface{}, duration time.Duration, deadline time.Time) *Ite return i } -//Touch increases the expiry time on the item by the TTL +// Touch increases the expiry time on the item by the TTL func (i *Item) Touch() { i.Lock() expiration := time.Now().Add(i.ttl) @@ -33,7 +33,7 @@ func (i *Item) Touch() { i.Unlock() } -//Expired returns if the item has passed its expiry time +// Expired returns if the item has passed its expiry time func (i *Item) Expired() bool { var value bool i.RLock() @@ -46,7 +46,7 @@ func (i *Item) Expired() bool { return value } -//GetValue represents the value of the item in the map +// GetValue represents the value of the item in the map func (i *Item) GetValue() interface{} { return i.data } diff --git a/opt.go b/opt.go index d1336a3..44ef29a 100644 --- a/opt.go +++ b/opt.go @@ -21,28 +21,28 @@ func defaultCacheOptions() cacheOptions { // CacheOption configures how we set up the cache map type CacheOption func(options *cacheOptions) -//WithShardSize With a custom sub map shard size +// WithShardSize With a custom sub map shard size func WithShardSize(shardSize int) CacheOption { return func(o *cacheOptions) { o.shardCount = shardSize } } -//WithDefaultTTL Sets the default duration for items stored +// WithDefaultTTL Sets the default duration for items stored func WithDefaultTTL(ttl time.Duration) CacheOption { return func(o *cacheOptions) { o.defaultCacheDuration = ttl } } -//WithCleanupDuration Sets how frequently to cleanup expired items +// WithCleanupDuration Sets how frequently to cleanup expired items func WithCleanupDuration(ttl time.Duration) CacheOption { return func(o *cacheOptions) { o.cleanupDuration = ttl } } -//WithMaxLifetime Sets the maximum amount of time an item can exist within the cache +// WithMaxLifetime Sets the maximum amount of time an item can exist within the cache func WithMaxLifetime(ttl time.Duration) CacheOption { return func(o *cacheOptions) { o.maxLifetime = ttl