Skip to content

Commit

Permalink
Fix typos, add doc (#78)
Browse files Browse the repository at this point in the history
* Update lru.go

fix typo

* Update lfu.go

Fix typo

* Update arc.go

Fix typo

* fix typos. Add doc in the interface
  • Loading branch information
sebastien-rosset authored Jun 10, 2021
1 parent a95af3e commit ecee3be
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion arc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lfu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lru.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit ecee3be

Please sign in to comment.