forked from eolinker/apinto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhangzeyi
committed
Oct 11, 2022
1 parent
e60684d
commit aa29d00
Showing
3 changed files
with
26 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,31 @@ | ||
package cache | ||
|
||
//todo 本地缓存demo | ||
import ( | ||
"encoding/json" | ||
"github.com/coocood/freecache" | ||
) | ||
|
||
type Cache struct { | ||
var freeCache *freecache.Cache | ||
|
||
func NewCache() { | ||
freeCache = freecache.NewCache(0) | ||
} | ||
|
||
type ResponseData struct { | ||
Header map[string]string | ||
Body []byte | ||
} | ||
|
||
func SetCache(uri string, cache *Cache, validTime int) { | ||
|
||
func SetCache(uri string, data *ResponseData, validTime int) { | ||
bytes, _ := json.Marshal(data) | ||
_ = freeCache.Set([]byte(uri), bytes, validTime) | ||
} | ||
|
||
func GetCache(uri string) *Cache { | ||
return nil | ||
func GetCache(uri string) *ResponseData { | ||
bytes, _ := freeCache.Get([]byte(uri)) | ||
data := new(ResponseData) | ||
if err := json.Unmarshal(bytes, data); err != nil { | ||
return nil | ||
} | ||
return data | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters