diff --git a/arc.go b/arc.go index e2015e9..7d0a012 100644 --- a/arc.go +++ b/arc.go @@ -172,7 +172,7 @@ func (c *ARC) Get(key interface{}) (interface{}, error) { } // GetIFPresent gets a value from cache pool using key if it exists. -// If it dose not exists key, returns KeyNotFoundError. +// If it does not exists key, returns KeyNotFoundError. // And send a request which refresh value for specified key if cache object has LoaderFunc. func (c *ARC) GetIFPresent(key interface{}) (interface{}, error) { v, err := c.get(key, false) diff --git a/cache.go b/cache.go index e13e6f1..0ae51bf 100644 --- a/cache.go +++ b/cache.go @@ -17,16 +17,32 @@ const ( var KeyNotFoundError = errors.New("Key not found.") type Cache interface { + // Set inserts or updates the specified key-value pair. Set(key, value interface{}) error + // SetWithExpire inserts or updates the specified key-value pair with an expiration time. SetWithExpire(key, value interface{}, expiration time.Duration) error + // Get returns the value for the specified key if it is present in the cache. + // If the key is not present in the cache and the cache has LoaderFunc, + // invoke the `LoaderFunc` function and inserts the key-value pair in the cache. + // If the key is not present in the cache and the cache does not have a LoaderFunc, + // return KeyNotFoundError. Get(key interface{}) (interface{}, error) + // GetIFPresent returns the value for the specified key if it is present in the cache. + // Return KeyNotFoundError if the key is not present. GetIFPresent(key interface{}) (interface{}, error) + // GetAll returns a map containing all key-value pairs in the cache. GetALL(checkExpired bool) map[interface{}]interface{} get(key interface{}, onLoad bool) (interface{}, error) + // Remove removes the specified key from the cache if the key is present. + // Returns true if the key was present and the key has been deleted. Remove(key interface{}) bool + // Purge removes all key-value pairs from the cache. Purge() + // Keys returns a slice containing all keys in the cache. Keys(checkExpired bool) []interface{} + // Len returns the number of items in the cache. Len(checkExpired bool) int + // Has returns true if the key exists in the cache. Has(key interface{}) bool statsAccessor diff --git a/lfu.go b/lfu.go index 9a4e3df..610843e 100644 --- a/lfu.go +++ b/lfu.go @@ -112,7 +112,7 @@ func (c *LFUCache) set(key, value interface{}) (interface{}, error) { } // Get a value from cache pool using key if it exists. -// If it dose not exists key and has LoaderFunc, +// If it does not exists key and has LoaderFunc, // generate a value using `LoaderFunc` method returns value. func (c *LFUCache) Get(key interface{}) (interface{}, error) { v, err := c.get(key, false) @@ -123,7 +123,7 @@ func (c *LFUCache) Get(key interface{}) (interface{}, error) { } // GetIFPresent gets a value from cache pool using key if it exists. -// If it dose not exists key, returns KeyNotFoundError. +// If it does not exists key, returns KeyNotFoundError. // And send a request which refresh value for specified key if cache object has LoaderFunc. func (c *LFUCache) GetIFPresent(key interface{}) (interface{}, error) { v, err := c.get(key, false) diff --git a/lru.go b/lru.go index a85d660..7d79a8f 100644 --- a/lru.go +++ b/lru.go @@ -89,7 +89,7 @@ func (c *LRUCache) SetWithExpire(key, value interface{}, expiration time.Duratio } // Get a value from cache pool using key if it exists. -// If it dose not exists key and has LoaderFunc, +// If it does not exists key and has LoaderFunc, // generate a value using `LoaderFunc` method returns value. func (c *LRUCache) Get(key interface{}) (interface{}, error) { v, err := c.get(key, false) @@ -100,7 +100,7 @@ func (c *LRUCache) Get(key interface{}) (interface{}, error) { } // GetIFPresent gets a value from cache pool using key if it exists. -// If it dose not exists key, returns KeyNotFoundError. +// If it does not exists key, returns KeyNotFoundError. // And send a request which refresh value for specified key if cache object has LoaderFunc. func (c *LRUCache) GetIFPresent(key interface{}) (interface{}, error) { v, err := c.get(key, false) diff --git a/simple.go b/simple.go index 7310af1..956d40a 100644 --- a/simple.go +++ b/simple.go @@ -87,7 +87,7 @@ func (c *SimpleCache) set(key, value interface{}) (interface{}, error) { } // Get a value from cache pool using key if it exists. -// If it dose not exists key and has LoaderFunc, +// If it does not exists key and has LoaderFunc, // generate a value using `LoaderFunc` method returns value. func (c *SimpleCache) Get(key interface{}) (interface{}, error) { v, err := c.get(key, false) @@ -98,7 +98,7 @@ func (c *SimpleCache) Get(key interface{}) (interface{}, error) { } // GetIFPresent gets a value from cache pool using key if it exists. -// If it dose not exists key, returns KeyNotFoundError. +// If it does not exists key, returns KeyNotFoundError. // And send a request which refresh value for specified key if cache object has LoaderFunc. func (c *SimpleCache) GetIFPresent(key interface{}) (interface{}, error) { v, err := c.get(key, false)