Skip to content

Commit e922a47

Browse files
committed
improt path, sync with updated interface and readme update
1 parent 8024a97 commit e922a47

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ High performance, eviction modes (TTL, NoTTL, Slide), goroutine safe inmemory ca
1212
## Installation
1313

1414
```bash
15-
go get -u aahframework.org/cache/inmemory
15+
go get -u aahframework.org/cache/provider/inmemory
1616
```
1717

1818
Visit official website https://aahframework.org to learn more about `aah` framework.

inmemory.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Copyright (c) Jeevanandam M. (https://github.com/jeevatkm)
2-
// aahframework.org/cache/inmemory source code and usage is governed by a MIT style
2+
// aahframework.org/cache/provider/inmemory source code and usage is governed by a MIT style
33
// license that can be found in the LICENSE file.
44

5-
package inmemory // import "aahframework.org/cache/inmemory"
5+
package inmemory // import "aahframework.org/cache/provider/inmemory"
66

77
import (
88
"sync"
@@ -88,13 +88,15 @@ func (im *inMemory) Get(k string) interface{} {
8888

8989
// GetOrPut method returns the cached entry for the given key if it exists otherwise
9090
// it puts the new entry into cache store and returns the value.
91-
func (im *inMemory) GetOrPut(k string, v interface{}, d time.Duration) interface{} {
91+
func (im *inMemory) GetOrPut(k string, v interface{}, d time.Duration) (interface{}, error) {
9292
ev := im.Get(k)
9393
if ev == nil {
94-
_ = im.put(k, v, d)
95-
return v
94+
if err := im.put(k, v, d); err != nil {
95+
return nil, err
96+
}
97+
return v, nil
9698
}
97-
return ev
99+
return ev, nil
98100
}
99101

100102
// Put method adds the cache entry with specified expiration. Returns error
@@ -104,10 +106,11 @@ func (im *inMemory) Put(k string, v interface{}, d time.Duration) error {
104106
}
105107

106108
// Delete method deletes the cache entry from cache store.
107-
func (im *inMemory) Delete(k string) {
109+
func (im *inMemory) Delete(k string) error {
108110
im.mu.Lock()
109111
delete(im.entries, k)
110112
im.mu.Unlock()
113+
return nil
111114
}
112115

113116
// Exists method checks given key exists in cache store and its not expried.
@@ -116,10 +119,11 @@ func (im *inMemory) Exists(k string) bool {
116119
}
117120

118121
// Flush methods flushes(deletes) all the cache entries from cache.
119-
func (im *inMemory) Flush() {
122+
func (im *inMemory) Flush() error {
120123
im.mu.Lock()
121124
im.entries = make(map[string]entry)
122125
im.mu.Unlock()
126+
return nil
123127
}
124128

125129
//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾

0 commit comments

Comments
 (0)