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
77import (
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